Let $x$ and $y$ be integers such that $3^x=2+y^2$. Note that $2+y^2>1$ and hence $x>0$.
In the ring $\Bbb{Z}[\sqrt{-2}]$ the element $3$ factors as $3=(1+\sqrt{-2})(1-\sqrt{-2})$, and we have
$$3^x=(y+\sqrt{-2})(y-\sqrt{-2}).$$
The gcd of the two factors on the right hand side divides
$$(y+\sqrt{-2})-(y-\sqrt{-2})=2\sqrt{-2}=-(\sqrt{-2})^3,$$
and it also divides $3^x$, and so the two factors are coprime. Because $\Bbb{Z}[\sqrt{-2}]$ is a unique factorization domain, it follows that $y+\sqrt{-2}=(1+\sqrt{-2})^x$ and $y-\sqrt{-2}=(1-\sqrt{-2})^x$.
I'll leave it for you (for now) to check that the coefficient of $\sqrt{-2}$ in the expansion of $(1+\sqrt{-2})^x$ equals $1$ if and only if $x=1$ or $x=3$.