Example 5 Find all pairs of integers $(x, y)$ such that
$$
1+2^{x}+2^{2 x+1}=y^{2} \text {. }
$$
(47th IMO)
When $x=-1$, the left side is 2, which is not a perfect square; when $x \leqslant -2$, the left side is not an integer.

Let $(x, y)$ be a solution to this equation. Then $x \geqslant 0$ and $(x, -y)$ is also a solution.

When $x=0$, $y= \pm 2$, the equation has solutions $(0,2)$, $(0,-2)$.
When $x>0$, let $(x, y)$ be a solution, and assume $y>0$ without loss of generality.
The original equation is
$$
2^{x}\left(1+2^{x+1}\right)=(y+1)(y-1) \text {. }
$$

Thus, $y-1$ and $y+1$ are both even, and only one of them is a multiple of 4.

Therefore, $x \geqslant 3$, and one of the factors is divisible by $2^{x-1}$ but not by $2^{x}$.

Hence, we can set $y=2^{x-1} m+\varepsilon$, where $m$ is a positive 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-m \varepsilon=2^{x-2}\left(m^{2}-8\right)$.
When $\varepsilon=1$,
$$
2^{x-2}\left(m^{2}-8\right)=1-m \varepsilon \leqslant 0
$$
$\Rightarrow m^{2}-8 \leqslant 0$.
Hence, the positive odd number $m=1$, and equation (1) does not hold.
When $\varepsilon=-1$, noting that $x \geqslant 3$, we have
$$
1+m=2^{x-2}\left(m^{2}-8\right) \geqslant 2\left(m^{2}-8\right) \text {, }
$$

which simplifies to $2 m^{2}-m-17 \leqslant 0$.
Thus, $m \leqslant 3$.
At this point, only the positive odd number $m=3$ makes equation (1) hold.
Therefore, $x=4, y=23$.

In summary, all positive integer pairs are
$$
(x, y)=(0,2),(0,-2),(4,23),(4,-23) .
$$