It is demonstrated by means of the optimal control theory that the energy cost of the spin-orbit torque induced reversal of a nanomagnet with perpendicular anisotropy can be strongly reduced by proper shaping of both in-plane components of the current pulse. The time dependence of the optimal switching pulse that minimizes the energy cost associated with joule heating is derived analytically in terms of the required reversal time and material properties. The optimal reversal time providing a tradeoff between the switching speed and energy efficiency is obtained. A sweet-spot balance between the fieldlike and dampinglike components of the spin-orbit torque is discovered; it permits for a particularly efficient switching by a down-chirped rotating current pulse whose duration does not need to be adjusted precisely.