I looked in other questions but I didn't find any answers regarding quadratic integer rings. Apologies if I missed it.
Given the ring $\mathbb{Z}[\sqrt{n}]$ where $n$ is a square-free positive integer, I would like to find the fundamental unit (i.e. some $a + b\sqrt{n}$ such that $\langle a + b\sqrt{n}\rangle = \mathbb{Z}[\sqrt{n}]^\times$, the units of $\mathbb{Z}[\sqrt{n}]$). I do know if I take the smallest $y$ such that $ny^2$ is of the form $x^2 \pm 1$, I get a unit, $x + y\sqrt{n}$. After all, we have $ny^2 = x^2 \pm 1$, so $ny^2 - x^2 = \pm 1$, meaning that $N(x + y\sqrt{n}) = x^2 - ny^2 = \mp 1$ ($N$ is just a standard Euclidean function). Since this particular Euclidean function is also multiplicative we know that any power of $x + y\sqrt{n}$ is also a unit. However, this is where I get stuck. Is this $x + y\sqrt{n}$ indeed a fundamental unit? If so, how do I show it can generate all units? If not, how do I find the actual fundamental unit?
It certainly has been discussed on MSE how to find a fundamental unit for the unit group of the ring of integers of a real quadratic number field $\mathbb{Q}(\sqrt{n})$. A nice survey, how to use continued fractions, and a table with examples for squarefree $n\le 21$ is given here.
Remark: The ring of integers in $\mathbb{Q}(\sqrt{n})$ is not always $\mathbb{Z}(\sqrt{n})$. This is only true for $n\equiv 2,3\bmod 4$. For the remaining case $n\equiv 1 \bmod 4$ (note that $n$ is squarefree), it is slightly different. An example here, with $n=141$ is discussed here on MSE. The result is as follows: since $\sqrt{141}=[11,\overline{1,6,1,22}]$, we have that $95+8\sqrt{141}$ is a fundamental unit!