I want to prove:
Let $(X,\mathcal{O}_X)$ be a locally ringed space, $f\in\Gamma(X,\mathcal{O}_X)$ and $U_f:=\{x\in X: f_x\in \mathcal{O}_{X,x}^*\}$ $\Rightarrow$ $f\in\Gamma(U_f,\mathcal{O}_X)^*$
I tried to use that $f_x$ is a unit in $\mathcal{O}_{X,x}$ $\forall x\in U_f$, hence in every local ring $\mathcal{O}_{X,x}$ there exists an inverse $f^{-1}_x$. Then for all $x\in U_f$ I chose an open set $U_x$ such that $x\in U_x\subset U_f$ and $g_x\in\Gamma(U_x,\mathcal{O}_X)$ such that $(g_x)_x=f^{-1}_x$. Like this I get an open covering $U_f=\bigcup_{x\in U_f} U_x$; now I would like to see that $g_x{\vert {U_x\cap U_y}}=g_y\vert{U_x\cap U_y}$ in order to get a section $g\in\Gamma(U_f,\mathcal{O}_X)$ such that $g_{\vert U_x}=g_x$. The injectivity of $\Gamma(U_f,\mathcal{O}_X)\rightarrow \Pi_{x\in U_f}\mathcal{O}_{X,x}$ would settle the proof.
So does it work like that and how could I settle the missing part? I am sure it is easy but right now I dont see it. Thanks in advance
You can finish your proof as follows:
1) By shrinking $U_x$ if necessary, you may assume that $g_x f=1$ on $U_x$: for this, just use the definition of the stalk, particularly what does the identity "$g_x f=1 \text{ in }\mathcal{\mathcal{O}_{X,x}}$" mean.
2) Now, just observe that both $g_x$ and $g_y$ are inverses to $f$ when restricted to $U_x \cap U_y.$ Since an inverse to an element is always unique, the have to agree.
Thus, you can glue these $g_x$'s to a $g$ defined on $U_f$.