4. Find all integer pairs $(x, y)$ such that
$$
1+2^{x}+2^{2 x+1}=y^{2} .
$$
4. If $(x, y)$ is a solution, then $x \geqslant 0, (x, -y)$ is also a solution.

When $x=0$, the solutions are $(0,2), (0,-2)$.
Assume $(x, y)$ is a solution, $x>0$. Without loss of generality, let $y>0$.
Thus, the original equation is equivalent to
$$
2^{x}\left(1+2^{x+1}\right)=(y-1)(y+1) \text {. }
$$

Therefore, $y-1$ and $y+1$ are even numbers, with exactly one being divisible by 4. Hence, $x \geqslant 3$, and one of the factors is divisible by $2^{x-1}$ but not by $2^{x}$.
So, $y=2^{x-1} m+\varepsilon$, where $m$ is an odd number, and $\varepsilon= \pm 1$.
Substituting into the original equation, we get
$$
\begin{array}{l}
2^{x}\left(1+2^{x+1}\right)=\left(2^{x-1} m+\varepsilon\right)^{2}-1 \\
=2^{2 x-2} m^{2}+2^{x} m \varepsilon,
\end{array}
$$

which simplifies to $1+2^{x+1}=2^{x-2} m^{2}+m \varepsilon$.
Thus, $1-\varepsilon m=2^{x-2}\left(m^{2}-8\right)$.
When $\varepsilon=1$, we have $m^{2}-8 \leqslant 0$, i.e., $m=1$, which does not satisfy the equation.
When $\varepsilon=-1$, we have
$$
1+m=2^{x-2}\left(m^{2}-8\right) \geqslant 2\left(m^{2}-8\right),
$$

which implies
$$
2 m^{2}-m-17 \leqslant 0 \text {. }
$$

Therefore, $m \leqslant 3$.
On the other hand, $m \neq 1$, and since $m$ is odd, we have $m=3$.
Thus, $x=4, y=23$.
Therefore, all solutions are
$$
(0,2),(0,-2),(4,23),(4,-23) \text {. }
$$