If I charge 3 capacitors in series, then connect themin parallel, where does the remaining energy go? I'll get into the math straight away
$C_1, C_2, C_3$ each are charged to $q$. The energy is $$\frac{q^2}{2\left(\frac{1}{\frac{1}{C_1}\frac{1}{C_2}\frac{1}{C_3}}\right)}$$
$$\frac{1}{2}\left(\frac{q^2}{C_1} + \frac{q^2}{C_2} + \frac{q^2}{C_3}\right)$$
 If I then connect them in parallel, the energy now is
$$\frac{1}{2}\left(\frac{9q^2}{C_1 + C_2 + C_3}\right)$$
They are obviuosly not equal. Can someone tell me where the difference in energy goes (and also how it gets dissipated.)
 A: If all the capacitors are identical, then the voltages across each individual capacitor are equal.  When attaching them in parallel, no current flows and no energy is lost. 
If the capacitors are not identical, then there are different voltages across each capacitor.  Placing them in parallel causes current to flow.  The wires in the circuit will have some resistance and will cause energy loss as the current flows.  In addition, your equation for the energy in the steady-state case will not be correct.  When connected in parallel, the different capacitors will all have the same voltage, but not the same charge.  So saying each has charge $q$ after being attached is not valid.
In the case where the wires have very low resistance, energy will oscillate for a period of time between being stored entirely in the capacitors and being partially stored in the magnetic field due to inductance from the current flow.  
Let's do an example.  Assume $C_1$ is $1\text{F}$ and $C_2$ is $2\text{F}$, and both are charged with $q=1\text{C}$.
$$U = \frac{Q^2}{2C}$$
$$U_1 = 0.5\text{J}$$
$$U_2 = 0.25\text{J}$$
$$U_{tot} = 0.75\text{J}$$
This agrees with your first formula, because it's just a sum of the energy on each capacitor.
Connecting them in parallel means that each must have the same voltage.
$$V_1 = V_2$$
$$\frac{Q_1}{C_1} = \frac{Q_2}{C_2}$$
But the total charge is conserved so
$$Q_1 + Q_2 = 2\text{C}$$
$$Q_2 = 2\text{C} - Q_1$$
Solving these two equations means steady-state afterward is
$$Q_1 = 0.66\text{C}$$
$$Q_2 = 1.33\text{C}$$
And the energy in this configuration is
$$U_1 = \frac{(0.66\text{C})^2}{1\text{F}} = 0.22J$$
$$U_2 = \frac{(1.33\text{C})^2}{2\text{F}} = 0.44J$$
$$U_{tot} = 0.67J$$
So there was a bit of loss from attaching.  Oops.  Did this wrong the first time, but this agrees with your equation (modified for 2 caps)
$$U_{tot} = \frac{1}{2}\left(\frac{4q^2}{C_1 + C_2 + C_3}\right) = \frac{1}{2}\left(\frac{4(1\text{C})^2}{3\text{F}}\right) = 0.67\text{J}$$
A: It is not obvious that these are not equal. All capacitors being equal, it would seem that 3/2 ( q^2/C) is the first energy sum, and 9/6 (q^2/C) is the second sum. 
If, on the other hand, the capacitances are NOT equal, then the equal charges
imply unequal terminal voltages.   When two different-voltage capacitors
are connected, the final wire attachment makes an LRC circuit, which oscillates and damps down, eventually.  True, one can ignore the L part if the resistance
dominates (because energy 1/2 I^2 * L is negligible when I is an arbitrarily
small trickle after equilibration), or one can ignore the R part if L dominates
(because I^2 L can be large in the first phase of the first oscillation cycle,
when little heating has yet occurred).  Interrupting, however, the connection
when voltages are equal would leave energy in the inductor (because the oscillation condition does not have I and V zero at the same moment).
So, simplest case is to consider a resistor between the two capacitors.
You will find that resistive energy loss is the missing term in the energy
after connection.   Taking the limit, as R approaches zero, does  not
change the energy lost in making the connection.
