I'll do this a bit more generally.
Let $\mathbf{LRS}$ be the category of locally ringed spaces and $\mathbf{Aff}$ be the category of affine schemes.
For the unit: Take $(X,\mathcal O_X) \in \mathbf{LRS}$. We want to describe a map $\eta_X:X \to \mathrm{Spec}(\Gamma(X,\mathcal O_X))$. Take any point $x \in X$. Then the stalk $\mathcal O_{X,x}$ is a local ring, so it has a maximal ideal, call it $\mathfrak{m}_{X,x}$. We have a ring homomorphism $i_X:\Gamma(X,\mathcal O_X) \to \mathcal O_{X,x}$. Define $\eta_X(x)$ to be $i_X^{-1}(\mathfrak{m}_{X,x}) \in \mathrm{Spec}(\Gamma(X,\mathcal O_X))$.
Varying over $x$, we get a set-function $\eta_X$.
As the next step, we check that $\eta_X$ is continuous. It suffices the preimage of basic opens are open, so let $f \in \Gamma(X,\mathcal O_X)$. Take any $y \in \eta_X^{-1}(D(f))$, then $\eta_X(y) \in D(f)$, so $f \notin i_X^{-1}(\mathfrak{m}_{X,x})$, so $i_X(f)=f_x \notin \mathfrak{m}_{X,x}$. Thus $f_x$ is a unit in $\mathcal O_{X,x}$ (as it's not contained in the maximal ideal of that local ring). Write $1=f_x\cdot g$ for some $g \in \mathcal O_{X,x}$. Now unpack the definition of $\mathcal O_{X,x}$ as a directed colimit. The equation $1=f_x \cdot g$ being true must mean that there's some open subset $U \subset X$ containing $x$ such that $1=f|_U \cdot g$ (where I'm abusing notation with $g$ here). But for all points $y \in U$, we have that $f_y \notin \mathfrak{m}_{X,y}$, so working backwards, we get $U \subset \eta_X^{-1}(D(f))$, showing that $\eta_X^{-1}(D(f))$ is open.
Now we want to upgrade this to a map of locally ringed spaces. This means that , first of all, for all open $U \subset \mathrm{Spec}(\Gamma(X,\mathcal O_X))$, we want a ring map $\Gamma(U,\mathcal O_{\mathrm{Spec}(\Gamma(X,\mathcal O_X))}) \to \Gamma(\eta_X^{-1}(U),\mathcal O_X)$. By a standard gluing argument, it suffices to do this for basic opens. So we want for any $f \in \mathrm{Spec}(\Gamma(X,\mathcal O_X))$, a map $$\Gamma(X,\mathcal O_X)_f \to \Gamma(\eta_X^{-1}(D(f)),\mathcal O_X)$$
What is $\eta_X^{-1}(D(f))?$ We had this guy before, it's $\{x \in X \mid f_x \notin \mathfrak{m}_{X,x}\}:=U_f$. Now as above for any $x \in U_f$ we get that $f_x$ is a unit in $\mathcal O_{X,x}$, which implies (by a small exercise I'll leave open) that $f|_{U_f}$ is a unit in $\Gamma(U_f,\mathcal O_X)$. But this means that our ring map is induces by the restriction map $\Gamma(X,\mathcal O_X) \to \Gamma(U_f,\mathcal O_X)$ and the universal property of localization. To check that this is indeed a map of locally ringed spaces is an exercise in using the uniqueness part of the universal property of localization.
For the counit map: this is pretty easy. You'll find that by definition we have for any ring $A$ a natural isomorphism $\Gamma(\mathrm{Spec}(A),\mathcal O_{\mathrm{Spec}(A)})=A$, so (up to this natural isomorphism) we can take the identity as a counit.
I hope you'll forgive me that I don't check the triangle identities here, as this answer is already quite long despite being basically all formal.