An electromagnetic wave possesses energy from the electric and magnetic components. This w/u deals with the magnetic component of that energy by taking the example of a solenoid.

A solenoid is basically a conducting coil wrapped in a helix. When an electric current is run through the coil, it generates an opposing emf which must be overcome by the connected battery. Thus, the battery must do work to force a maximum current through the solenoid. This work is stored in the surrounding magnetic field. The circuit equation for a solenoid is

V= L(dI/dt) + RI
where I is the current flowing at a given time, V is the voltage across the solenoid, R is its resistance and L its self-inductance. The power required at any instance in the circuit is given by the product VI. Simply integrating this over time will yield the work done.
W= 1/2(LIo2)+RIo2
The first term on the right hand side is the inductively stored energy (i.e. that stored in the solenoidal magnetic field) while the second term is the energy dissipated resistively. Thus we have
Winductive=1/2(LIo2)= UM
where UM is the magnetic stored energy. In the case of an ideal solenoid (one that is infinitely long) the inductance L can be expressed in terms of the cross-sectional radius r, the length d and the number of turns N of the solenoid
where μo is the permeability of free space. In this case the magnetic field running through the solenoid is
Combining the previous three equations and noting that πr2d is simply the volume of the solenoid V one arrives at
Finally, divide by volume to obtain the magnetic field energy density, uM
The permeability may be changed by putting a soft iron core into the solenoid, greatly increasing the amount of magnetic energy that can be stored in the inductor.

See also electric field energy density and Poynting vector.

Source: (for a more rigorous derivation)