There is a small problem with your solution, since you don't know that $\sqrt{10}$ is irreducible, and so $2$ and $\sqrt{10}$ could have a common factor. The standard approach to deal with this is to use norms.
Define the norm $N(a+b\sqrt{10})=(a+b\sqrt{10})(a-b\sqrt{10})=a^2-10b^2$. The norm satisfies the property that $N(xy)=N(x)N(y)$.
The first observation is that $x$ is a unit if and only if $N(x)=\pm 1$, because $N(x)$ is a multiple of $x$ and $1=N(1)=N(xx^{-1})=N(x)N(x^{-1})$, and the only integer divisors of $1$ are $\pm 1$.
With this in mind, we can calculate $N(2)=4$ and $N(\sqrt{10})=-10$, and since the norms aren't multiples of each other, the numbers can't be multiples of each other. If they had a common non-unit factor, though, it would have to have norm $\pm 2$. So let us show that there are no elements with norm $\pm 2$.
Suppse $a^2-10b^2=\pm 2$. Reducing mod 10, we get $a^2\equiv \pm 2 \pmod{10}$, but no perfect square ends with a 2 or an 8, so this has no solutions.
Edit. I have now a complete answer.
Apologies, but the only way to solve this question I know makes use of factorization of ideals.
I will use the following well-known facts:
Fact 1. A Dedekind domain is a UFD if and only if it's a PID
Fact 2. A local Dedekind Domain is a PID
Fact 3. The localization of a Dedekind domain is a Dedekind domain.
Fact 4. A noetherian domain is a PID if and only if any maximal ideal is principal.
Since $D\not\equiv 1 [4]$, $R'=\mathbb{Z}[\sqrt{D}]$ is a Dedekind domain. Since $R=\mathbb{Z}_{(p)}[\sqrt{D}]$ is the localisation of $R'$ at $S=\mathbb{Z}\setminus p\mathbb{Z}$, $R$ is also a Dedekind domain (Fact 3).
In particular, $R$ is a UFD if and only if is a PID (Fact 1) . Since $R$ is a noetherian domain, $R$ is a PID if and only if every maximal ideal of $R$ is principal (Fact 4).
Since $R$ is a Dedekind domain (and not a field), maximal ideals are exactly nonzero prime ideals, which are $\mathfrak{p}_{(p)}$, where $\mathfrak{p}$ is a prime ideal of $R'$ not meeting $S$, that is a prime ideal of $R'$ containing $p$.
If $p$ is totally ramified or inert in $\mathbb{Q})(\sqrt{D})$,there is only one $\mathfrak{p}$ lying above $p.$ Thus $R$ is a local Dedekind domain , hence is a PID (Fact 2).
The case where $p$ splits corresponds to the case where $p\nmid D$ and $D$ is a square mod $p$. So, let $m\in\mathbb{Z}$ such that $D=m^2 [p]$ if $p$ is odd, and let $m=1$ if $p=2$.
We may write $D-m^2=kp, k\in\mathbb{Z}$.
Claim. One may choose $m$ such that $p\nmid k.$
Proof of the claim.
This it is true if $p=2$, since one may take $m=1$ and $D$ is not congruent to $1$ modulo $4$.
Assume that $p>2$. Pick any $m$ such that $D-m^2=kp$ for some $k\in\mathbb{Z}$.
Assume that $p\mid k$ for this choice of $m$ .Then $D-(m+p)^2=D-m^2-2mp-p^2=(k-2m-p)p$. Now since $p\nmid D$, we have
$p\nmid m$, and since $p$ is odd, $p\nmid 2m$. All in all, $p\nmid k-2m-p$. Henre, replacing $m$ par $m+p$, one may assume that $k\nmid p$ and we are done.
Let us go back to the split case.
The two prime ideals lying above $p$ are $\mathfrak{p}=(p,m+\sqrt{D})$ and $\mathfrak{p}^*=(p,m-\sqrt{D})$. Since $\mathfrak{p}^*$ is the image of $\mathfrak{p}$ under the nontrivial $\mathbb{Q}$-automorphism of $\mathbb{Q}(\sqrt{D})$, it is enough to show that $\mathfrak{p}_{(p)}$ is principal, using facts 1 and 4.
Now $(m+\sqrt{D})(-m+\sqrt{D})=D-m^2=kp$ for some integer $k$.
Since $p\nmid k$,we get $p=(m+\sqrt{D})\dfrac{-m+\sqrt{D}}{k}\in (m+\sqrt{D})_{(p)}$, and we have $\mathfrak{p}_{(p)}=(m+\sqrt{D})_{(p)}$.
Alternative proof. $R$ is a Dedekind domain, whose maximal ideals corresponds to prime ideals of $R'$ lying above $p$. Since these are in finite number, $R$ is a semi-local Dedekind domain. But a semi-local Dedekind domain is known to be a PID (see If R is a semilocal Dedekind Domain, then R is a PID. for example).
Greg
Best Answer
If $n$ is even, then $2$ divides $\sqrt{-n}^2=-n$ but does not divide $\sqrt{-n}$, so $2$ is a nonprime irreducible. In a UFD, all irreducibles are prime, so this shows $\mathbb{Z}[\sqrt{-n}]$ is not a UFD.
Similarly, if $n$ is odd, then $2$ divides $(1+\sqrt{-n})(1-\sqrt{-n})=1+n$ without dividing either of the factors, so again $2$ is a nonprime irreducible.
This argument works equally well for $n=3$, but fails for $n=1,2$, and in fact $\mathbb{Z}[\sqrt{-1}]$ and $\mathbb{Z}[\sqrt{-2}]$ are UFDs.