Electrostatic energy
Potential energy of a charge and of a system
Potential energy of a test charge
The electrostatic potential energy of a charge q placed at a point where a potential V exists is:
Ep = q * V
This energy represents the work that would need to be supplied against the electric forces to bring the charge from the reference (V = 0) to this point. The work of the electric forces between two positions A and B is then:
W(A->B) = Ep(A) - Ep(B) = q*(V(A) - V(B))
Interaction energy between two charges
For two point charges q1 and q2 separated by a distance r12, the interaction potential energy (the energy needed to bring them from infinity to this configuration) is:
Ep = k * q1 * q2 / r12
If q1 and q2 have the same sign, Ep > 0: work must be supplied to bring them closer together (they repel each other). If they have opposite signs, Ep < 0: the system releases energy as they come closer (they attract each other).
Energy of a system of N charges
For a system of N point charges, the total energy is the sum of the interaction energies of all distinct pairs:
Ep_total = sum over all pairs (i<j) of k * qi * qj / rij
For 3 charges, this gives 3 terms (pairs 1-2, 1-3, 2-3); for N charges, there are N*(N-1)/2 pairs to consider.
Classic pitfall
Never count a pair twice (Ep(1,2) and Ep(2,1) are the same physical energy). A common mistake is to sum over all ordered pairs (i,j) with i different from j, which artificially doubles the total energy.

