The formular to use is the electric potential energy: E=k(q1*q2)/r. With k=1/(4*pi*e0) being a constant that is ignored (or integrated in q). q1 and q2 are the charge e of an electron or -e for a proton. r is the distance that you can calculate dependant on d with pythagoras between the different particles (e-e, e-p, p-p). If you add these three terms together you get the total energy of the solid. Though for me this is only (-sqrt(2)+2)(q^2/d), which is a positive energy altogether. I am missing the factor 3, so still something is wrong…