Optimal control of heat engines in non-equilibrium statistical mechanics