In order to reduce the global energy consumption and avoid highest power peaks during operation of manufacturing systems, an optimization-based controller for selective switching on/off of peripheral devices in a test bench that emulates the energy consumption of a periodic system is proposed. First, energy consumption models for the test-bench devices are obtained based on data and subspace identification methods. Next, a control strategy is designed based on both optimization and receding horizon approach, considering the energy consumption models, operating constraints, and the real processes performed by peripheral devices. Thus, a control policy based on dynamical models of peripheral devices is proposed to reduce the energy consumption of the manufacturing systems without sacrificing the productivity. Afterward, the proposed strategy is validated in the test bench and comparing to a typical rule-based control scheme commonly used for these manufacturing systems. Based on the obtained results, reductions near 7% could be achieved allowing improvements in energy efficiency via minimization of the energy costs related to nominal power purchased.