Solution 1:

The localization of a UFD is a UFD provided you don't invert $0$.

Suppose $D$ is a UFD, and let $S$ be a multiplicative subset that does not contain $0$. Let $T$ be the set of all irreducibles that divide an element of $S$, and let $M$ be the set of all irreducibles not in $T$.

Claim. $p\in T$ if and only if the image of $p$ in $S^{-1}D$ is a unit.

Indeed, if $p\in T$, then there exists $s\in S$ such that $p|s$; let $x\in D$ with $px=s$. Then $$\frac{ps}{s}\cdot\frac{x}{s} = \frac{pxs}{ss} = \frac{ss}{ss} = 1_{S^{-1}D},$$ so the image of $p$ in $S^{-1}D$ is a unit. Conversely, if the image of $p$ is a unit, then there exist $t\in S$ and $x\in D$ such that $\frac{ps}{s}\cdot\frac{x}{t} = 1_{S^{-1}D}$, then $\frac{pxs}{st}=\frac{s}{s}$, hence $pxs^2 = s^2t$, hence $px=t \in S$, so $p\in T$, since $p$ divides an element of $S$. $\Box$

Claim. If $p\in M$, then the image of $p$ in $S^{-1}D$ is irreducible.

Indeed, suppose that $\frac{ps}{s} = \frac{x}{t}\frac{y}{t'} = \frac{xy}{tt'}$. Then $pstt' = xys$. Since $p$ does not divide any element of $S$, and $D$ is a UFD, an associate of $p$ appears exactly once in the factorization of $xys$ into irreducibles, and it must divide either $x$ or $y$, but not both, and all other irreducibles that appear in the factorization of $xys$ must lie in $T$. Therefore, either $\frac{x}{t}$ is a unit, or $\frac{y}{t'}$ is a unit. So $\frac{ps}{s}$ is irreducible (it is not $0$ or a unit by the previous claim).

Since $S^{-1}D$ can be embedded in the field of fraction of $D$, it follows that $S^{-1}D$ is a domain. Let $\frac{a}{s}\in S^{-1}D$; let $$a = up_1^{b_1}\cdots p_r^{b_r}q_1^{c_1}\cdots q_t^{c_t}$$ be a factorization of $a$ in $D$, where $u$ is a unit of $D$, $p_1,\ldots,p_r\in T$, and $q_1,\ldots,q_t\in M$. For a fixed $s\in S$, we have $$\frac{a}{s} = \frac{u}{s}\left(\frac{p_1s}{s}\right)^{b_1}\cdots\left(\frac{p_rs}{s}\right)^{b_r}\left(\frac{q_1s}{s}\right)^{c_1}\cdots\left(\frac{q_ts}{s}\right)^{c_t}$$ is a factorization of $\frac{a}{s}$ into a unit times a product of irreducibles (namely, the images of $q_i$ in $S^{-1}D$).

To verify uniqueness up to units, cross multiply and use unique factorization in $D$ and the claims above.

Solution 2:

One slick way is via Kaplansky's characterization: a domain is a UFD iff every nonzero prime ideal contains a nonzero prime. This is easily seen to be preserved by localization, hence the proof. Alternatively, proceed directly by showing that primes stay prime in the localization if they survive (don't become units). Thus UFD localizations are characterized by the set of primes that survive.

The converse is also true for atomic domains, i.e. domains where nonzero nonunits factor into atoms (irreducibles). Namely, if $\rm\:D\:$ is an atomic domain and $\rm\:S\:$ is a saturated submonoid of $\rm\:D^*$ generated by primes, then $\rm\: D_S$ UFD $\rm\:\Rightarrow\:D$ UFD $\:\!$ (a.k.a. Nagata's Lemma). This yields a slick proof of $\rm\:D$ UFD $\rm\Rightarrow D[x]$ UFD, viz. $\rm\:S = D^*\:$ is generated by primes, so localizing yields the UFD $\rm\:F[x],\:$ $\rm\:F =\,$ fraction field of $\rm\:D.\:$ Thus $\rm\:D[x]\:$ is a UFD, by Nagata's Lemma. This gives a more conceptual, more structural view of the essence of the matter (vs. traditional argument by Gauss' Lemma).