Let $d \in \mathbb Z$ and let $\sqrt{d} \in \mathbb C$ be a square root of $d$. Consider the subring of $\mathbb C$, $$\mathbb Z[{d}]=\{a+b\sqrt{d}: a,b \in \mathbb Z \}$$ and we define the norm of an element in $\mathbb Z[\sqrt{d}]$ by $N(a+b\sqrt{d})=a^2-db^2$.
Prove the following:
1) $z \in \mathbb Z[\sqrt{d}]$ is a unit if and only if $N(z)=\pm1$.
2) The ring $\mathbb Z[\sqrt{d}]$ is prefactorial, i.e., every non zero element which is not a unit can be written as product of irreducible elements.
I'll write what I could do:
1) Suppose $N(z)=\pm 1$, where $z=a+b\sqrt{d}$. Then $(a+b\sqrt{d})\dfrac{a-b\sqrt{d}}{a^2-b^2d}=1$, so the candidate for $z^{-1}$ is $\dfrac{a-b\sqrt{d}}{a^2-b^2d}$. From here it is clear that if $N(z)=\pm 1 \implies z^{-1} \in Z[\sqrt{d}]$. I couldn't prove the other implication.
I don't know what to do in 2), I would appreciate suggestions.