Why is $f|X_f$ a unit in $\mathcal O_X(X_f)$? I am on the last part of this problem in Hartshorne.  I think what I am stuck on comes down to showing that $f|X_f$ is a unit in $\mathcal O_X(X_f)$:

I don't see why this is.  In general, if $Y$ is a scheme, and $s \in \mathcal O_Y(Y)$ has the property that for each $y \in Y$, the stalk $s_y$ does not lie in the maximal ideal $\mathfrak m_y$, I don't think that $y$ needs to be a unit.
 A: The idea is to reduce to checking on affine schemes by covering $X_f$ by affine opens. (Note: in your situation, $X_f$ will play the role of what I've denoted $X$.)
Lemma: Let $U_i$ form an open cover of $X$.  $f\in\mathcal{O}_X(X)^\times$ if and only if $\left.f\right|_{U_i}\in \mathcal{O}_X(U_i)^\times$ for all $i$.
Proof: The "only if" direction is obvious, the "if" direction is an easy consequence of the sheaf property and uniqueness of inverses. Let $f_i$ denote the restriction of $f$ to $U_i$. Then for each $i$ there exists $g_i\in\mathcal{O}_X(U_i)$ such that $f_i g_i = 1$. Now, restricting to $U_i\cap U_j = U_{ij}$, you have
$$
\left.f_i\right|_{U_{ij}}\left.g_i\right|_{U_{ij}} = 1 = \left.f_j\right|_{U_{ij}}\left.g_j\right|_{U_{ij}}.
$$
Moreover, $\left.f_i\right|_{U_{ij}} = \left.f_j\right|_{U_{ij}}$, so uniqueness of multiplicative inverses implies that $\left.g_i\right|_{U_{ij}} = \left.g_j\right|_{U_{ij}}$ for all $i,j$. Hence, the local inverses glue to a global inverse of $f$.
Thus, it suffices to show the following:
Claim: Let $X = \operatorname{Spec}A$, and let $f\in\Gamma(X,\mathcal{O}_X) = A$. Then $f\in A^\times$ if and only if $f\not\in\mathfrak{p}$ for all prime ideals $\mathfrak{p}\subseteq A$.
Proof: Again, the "only if" direction is obvious. To see the "if" direction, suppose that $f\not\in A^\times$. Then $(f)\neq A$, so $(f)$ is contained in some maximal ideal (which is prime), so $f\in\mathfrak{p}$ for some prime ideal $\mathfrak{p}$. (As noted in the comments.)
