Optimization of energy conversion in monolithic superconducting magnets