Energy efficiency improvement and timely preventive maintenance (PM) are critical in manufacturing industry due to the rising energy cost, environmental concerns, and increasing requirements on system reliability. By strategically turning appropriate machines in down state, the corresponding energy consumption can be reduced, and at the meantime, the necessary PM works can be carried out to increase PM completion rate and reduce potential extra expense on PM during nonproduction shifts. However, there is usually a tradeoff between time dedicated to production and time available for energy saving and PM. In this paper, a systematic method is developed to identify opportunity windows (OWs) during which certain machines can be shut down to save energy and PM tasks can be performed while maintaining a desired production throughput. The method is based on stochastic serial production lines and real-time production data. A profit function is formulated to illustrate the tradeoff between energy cost savings and potential throughput loss. The profit function is used to justify the cost savings by utilizing the proposed OWs during production operation.