The first equality in the computation of $\mathbb E\left[X^2\right]$ follows from the fact that, for a non-negative random variable $Y$ with CDF $G$, we have that
$$ \mathbb E [Y]= \int_0^\infty y \,\mathrm d G(y) = \int_0^\infty (1-G(t))\,\mathrm d t. $$
You can find a proof of this here.
To see the first equality for $\mathbb E[X]$, we use the above result, along with the fact for a non-positive random variable $Y$ with CDF $G$,
$$ \mathbb E[Y] = \int_{-\infty}^0 y \,\mathrm d G(y) = -\int_{-\infty}^0 G(t) \, \mathrm d t. $$
You can prove this in a way similar to the analogous result for non-negative random variables.
Putting the two facts together allows us to write
\begin{align*}
\mathbb E [X] &= \int_{-\infty}^\infty x \,\mathrm d F_X (x) \\
&= \int_0^\infty x\,\mathrm d F_X (x) +\int_{-\infty}^0 x \mathrm d F_X (x) \\
&= \int_0^\infty (1-F_X(t)) \,\mathrm d t - \int_{-\infty}^0 F_X(t)\,\mathrm d t.
\end{align*}