Energy Stored in the Field
Assembling a set of charges takes work, and that work is recoverable, so it is stored energy. For point charges,
where is the potential at charge due to all the others. The factor of prevents counting each pair twice.
The same energy can be attributed to the field itself, with an energy density
or in a dielectric. Integrating over all space gives the same total as the charge-based sum, the two are alternative bookkeeping for one quantity, and the field picture becomes essential once radiation is involved, since then the energy is demonstrably out there travelling.
For a capacitor the stored energy takes three equivalent forms:
Choosing among them matters, because which is constant depends on the experiment. Pull the plates apart at fixed charge and rises as falls, you do work against the attraction. Do it at fixed voltage, with a battery connected, and falls, because charge flows back into the battery.
Forces follow from differentiating the energy. At fixed charge, : the system moves so as to lower its energy. The attraction between capacitor plates comes straight out of this, and so does the fact that a dielectric slab is always pulled into the gap, doing so raises and lowers .
Common pitfall: using when the charge is what is held fixed. All three expressions are correct at any instant, but only one has a constant in front during a given process. Pick the form whose variable your experiment actually holds still.