Let us consider a capacitor of capacitance C and potential difference V between the plates.
Let the charge on one plate be +q and -q on the other.
Suppose the capacitor is being charged gradually.
Now,at any stage the charge on capacitor is q.
Therefore, the potential difference = qC
Small amount of work doe in giving n additional charge dq to the capacitor is
dW= qC∗dq
Total work done in giving a charge Q to the capacitor is
W=∫dW
W= ∫Q0QCdq
W = Q2C
Energy = E
E= Q22C = CV22 = QV2
The energy is stored in the form of potential energy.