A new approach to optimal energy management with discrete control