1. Consider a capacitor of capacitance C. The energy required to charge the capacitor to charge ##Q_0## is the energy that will be stored in the e-field between its plates. Why it is required energy to charge from charge 0 to charge ##Q_0##? Consider a capacitor that is already charged at charge ##q## and we want to charge it to charge ##q+dq##. Therefore we have to do work against the E-field that exists between its plates to transfer charge +dq from the negative plate to the positive plate and this work is ##dW=Vdq=\frac{q}{C}dq## . So the total work done to charge it from 0 to charge ##Q_0## is ##W=\int dW=\int_0^{Q_0}\frac{q}{C}dq=\frac{1}{2}\frac{Q_0^2}{C}## and this work is stored as E-field energy in the E-field between its plates.
2. Consider an inductor of inductance L. The energy required to "charge" the inductor to current ##I_0## is the energy that will be stored in the magnetic field inside the turns of the coil. Energy is required because we know that an inductor "resists" a change to its current from ##I## to ##I+dI## (due to Lenz's law). The work required to change the current from ##I## to ##I+dI## is ##dW=VIdt=L\frac{dI}{dt}Idt=LIdI## so the total work required is ##W=\int dW=\int_0^{I_0}LIdI=\frac{1}{2}LI_0^2##.