  We consider a class of quantum heat engines consisting of two subsystems
interacting via a unitary transformation and coupled to two separate baths at
different temperatures $T_h > T_c$. The purpose of the engine is to extract
work due to the temperature difference. Its dynamics is not restricted to the
near equilibrium regime. The engine structure is determined by maximizing the
extracted work under various constraints. When this maximization is carried out
at finite power, the engine dynamics is described by well-defined temperatures
and satisfies the local version of the second law. In addition, its efficiency
is bounded from below by the Curzon-Ahlborn value $1-\sqrt{T_c/T_h}$ and from
above by the Carnot value $1-(T_c/T_h)$. The latter is reached|at finite
power|for a macroscopic engine, while the former is achieved in the equilibrium
limit $T_h\to T_c$. When the work is maximized at a zero power, even a small
(few-level) engine extracts work right at the Carnot efficiency.
