Solution (source code)

= Solution

Let $r$ be distance from the common centre. By <Gauss's law>, the <electric field> is radial and equals
$$
\boxed{
\mathbf E(r)=
\begin{cases}
0,&0\le r<R,\\[2mm]
\dfrac{Q_1}{4\pi\epsilon_0r^2}\,\widehat{\mathbf r},
&R<r<2R,\\[3mm]
\dfrac{Q_1+Q_2}{4\pi\epsilon_0r^2}\,\widehat{\mathbf r},
&r>2R.
\end{cases}}
$$
Taking the <electric potential> to vanish at infinity and requiring continuity across each shell gives
$$
\boxed{
\Phi(r)=\frac1{4\pi\epsilon_0}
\begin{cases}
\dfrac{Q_1}{R}+\dfrac{Q_2}{2R},&0\le r\le R,\\[3mm]
\dfrac{Q_1}{r}+\dfrac{Q_2}{2R},&R\le r\le2R,\\[3mm]
\dfrac{Q_1+Q_2}{r},&r\ge2R.
\end{cases}}
$$

The <electrostatic energy> is the integral of the electric-field energy density:
$$
U=\frac{\epsilon_0}{2}\int_{\mathbb R^3}|\mathbf E|^2\,dV.
$$
Only the two nonzero-field regions contribute, so
$$
U=\frac{Q_1^2}{8\pi\epsilon_0}
\int_R^{2R}\frac{dr}{r^2}
+\frac{(Q_1+Q_2)^2}{8\pi\epsilon_0}
\int_{2R}^{\infty}\frac{dr}{r^2}.
$$
Therefore
$$
\boxed{U
=\frac{Q_1^2+(Q_1+Q_2)^2}{16\pi\epsilon_0R}
=\frac{2Q_1^2+2Q_1Q_2+Q_2^2}{16\pi\epsilon_0R}}.
$$