# Energy conservation in electrostatics

If two charges $q_1$ and $q_2$ have opposite charges then the external agent does negative external work on the system to move $q_2$ from a large separation to place it at rest in a location with a smaller separation from $q_1$. This work decreases the energy stored in the system. How?

If $q_2$ and $q_1$ have opposite signs and begin with a small separation then the external agent must do positive work equal to $\Delta U$ in order to separate the charges to a large distance. Why is work positive in this case?

The net work on a system by external forces, $W_\text{net,ext}$, is equal to the change in energy of a system, $\Delta E_\text{tot}$. So, to figure out whether the total energy increases or decreases, you can determine what the sign of $W_\text{net,ext}$. One way to do that is to use the definition of work as the dot product between force and displacement.
A small amount of work $\mathrm dW$ by a force $\vec F$ during a displacement $\mathrm d \vec s$ is equal to the dot product $\mathrm dW = \vec F \cdot \mathrm d\vec s$ = $|\vec F ||\mathrm d\vec s|\cos\theta$. The cosine of the angle between the two vectors determines the sign of work.
If the external force $\vec F$ and the displacement are in the same direction, then $\cos\theta = \cos 0$ is positive. This is the case for your second situation in which the charges are moved apart: If $q_1$ and $q_2$ have opposite signs they attract. The external agent must exert a force on the moveable charge in a direction away from the other charge so that they don't accelerate toward each other. This is in the same direction as displacement, so the cosine yields a positive value, and thus the change in energy is positive.
For the first case, if the charges are to be moved closer to each other in a controlled manner, the force must again be away. This is in the opposite direction as displacement, so the cosine yields a negative value ($\cos \pi = -1$). A negative net work means a decrease in energy.