Here’s the story, though I leave it to others to furnish a proof or give a proper reference.
For $d\ge2$ and not a square, you get all solutions to the Pell equation $m^2-dn^2=\pm1$ by looking at the continued fraction expansion of $\sqrt d$. If $k=\lfloor\sqrt d\rfloor$, then your expansion looks like this:
$$
\sqrt d=k+\bigl[\frac1{\delta_1+}\>\frac1{\delta_2+}\cdots\frac1{\delta_{r-2}+}\>\frac1{\delta_{r-1}+}\>\frac1{2k+}\>\bigr]\,,
$$
where the part in brackets repeats infinitely. Then, every time you evaluate a convergent to the continued fraction just before the appearance of the $2k$, you’ll get a solution of Pell from the numerator $m$ and the denominator $n$. For instance, $\sqrt7=2+\frac1{1+}\,\frac1{1+}\,\frac1{1+}\,\frac1{4+}\,\cdots$, repeating with a period of length four. You evaluate $2+\frac1{1+}\,\frac1{1+}\,\frac1{1}=8/3$, and lo and behold, the first solution of $m^2-7n^2=\pm1$ is $m=8$, $n=3$.
For $d$ squarefree and incongruent to $1$ modulo $4$, this gives you all the units in $\Bbb Q(\sqrt{d}\,)$, but for $d\equiv1\pmod4$, it may happen that what you get is the cube of a unit. But as I recall, in that case, the primitive unit’s coordinates always will show up as the numerator and denominator of an earlier convergent.
In the case of a real quadratic field, the fundamental unit is the smallest unit of the form $ x + y \sqrt{d} $ such that $ x \geq 0 $ and $ y \geq 1 $. To see this, note that if $ x + y \sqrt{d} > 1 $ is a unit, we have that $ x^2 - dy^2 = \pm 1 $. Assume that $ x $ and $ y $ had different signs, then we would have
$$ x + y \sqrt{d} = \frac{\pm 1}{x - y \sqrt{d}} $$
and $ |x - y \sqrt{d}| \geq 1 $ since $ x $ and $ -y $ have the same sign. This is a contradiction, therefore $ x $ and $ y $ are both nonnegative in $ x + y \sqrt{d} $. Since the fundamental unit is the smallest unit greater than $ 1 $, it follows that we may simply look at units of the form $ x + y \sqrt{d} $ where $ x, y $ are nonnegative, which reduces the problem to a necessarily finite brute force search.
While Dirichlet's unit theorem necessarily implies that the above found unit must be the fundamental unit, there is a more elementary proof of this fact. Assume that $ \varepsilon $ is the smallest unit greater than $ 1 $, and $ x $ is any unit greater than $ 1 $. We want to show that $ x $ is a power of $ \varepsilon $. Since the sequence $ a_n = \varepsilon^n $ diverges, there is a greatest integer $ n $ such that $ a_n = \varepsilon^n \leq x $. Then, $ x/\varepsilon^n $ is a unit $ \geq 1 $, but it is less than $ \varepsilon $ since $ x < \varepsilon^{n+1} $. By the definition of $ \varepsilon $, the only unit in the interval $ [1, \varepsilon) $ is $ 1 $, so it follows that $ x = \varepsilon^n $.
A more sophisticated algorithm to find the fundamental unit involves continued fractions, see these lecture notes for further information.
Best Answer
Assume that $m \geq 2$.
If $a + b\sqrt{m^2 - 1}$ is a unit (with $a, b\in \Bbb Z_{> 0}$), then we have $a^2 - (m^2 - 1)b^2 = \pm 1$.
It is then easy to see that $a \geq m$, because $a^2 = (m^2 - 1)b^2 \pm 1\geq m^2 - 2$.
Therefore, $(a, b) = (m, 1)$ is the smallest solution to the Pell equation, and hence the fundamental unit of the order $\Bbb Z[\sqrt{m^2 - 1}]$ (which is equal to the ring of integers of $\Bbb Q(\sqrt{m^2 - 1})$ if $m^2 - 1$ is square free).