Suppose we have a charged capacitor connected to a battery. Now we push the plates of the capacitor away from each other decreasing capacitance and hence energy stored in the capacitor decreases. Now where did this energy go? Also some charge must be flowing to the battery, so is the energy getting stored in the battery? How do I relate the work done by the force and these things? Also what is the heat released?
Suppose that you double the separation of the plates of a parallel plate capacitor of initial capacitance $C$ which is connected to a battery of emf $V$.
The capacitance of the capacitor become $\frac C 2$ and the energy stored in the capacitor changes from $\frac 12 CV^2$ to $\frac 1 2 \frac C 2 V^2$.
There is a decrease in the energy stored in the capacitor of $\frac 1 4 CV^2$.
Originally the capacitor had a charge $Q= CV$ but after increasing the separation of the plates at constant $V$ the charge stored is $\frac Q 2$.
The work done in moving the charge $\frac Q 2$ through the battery is $\frac Q 2 V = \frac 1 2 CV^2$.
The missing $\frac 1 2 CV^2 - \frac 1 4 CV^2 = \frac 1 4 CV^2$ is the work done by an external force (you?) in separating the capacitor plates.
If there was resistance in the circuit then the external force would have to do more work to move the charge $\frac Q 2$ around the circuit which would manifest itself as the resistor heating up.