In recent years, the topic of sustainable manufacturing system design with energy saving features has received increasing attention. For a typical production line setting, the machines are subject to random breakdown and restart besides blockage and starvation, and they are usually connected via buffer areas with finite capacity. In the present study, the energy consumption of the serial production line with two Bernoulli machines is considered, with an aim to minimize the total energy consumption under a desired production rate. The energy consumption of the two machine system is composed of the energy needed to set up, for keeping machines idle, and for actual manufacturing. In order to minimize the total energy expenditure, a nonlinear fractional polynomial optimization model is constructed, which is first converted to a nonlinear polynomial optimization problem. Then the property of the total energy cost is analyzed via the sum of squares (SOS) method. To speed up the solving process, a new heuristic approach named ECS-algorithm is proposed considering the monotonicity and local optimality of the energy cost function. Finally, by presenting optimal configurations of the production line with different throughputs, buffer capacities, and energy parameters, a simulation based study is performed to validate the SOS and ECS algorithms.