In general, one asks for a result like $U,V$ must intersect if something is true about their dimensions when $U,V$ are both closed inside some irreducible space - for instance, without requiring that they're closed, if they're both contained in lower-dimensional closed subvarieties and these subvarieties have no common components, you can often just delete the intersection points from one of $U$ or $V$ without changing anything about the circumstances of the problem. (The case of $U,V$ both open is trivial: a space is irreducible iff any two open subsets intersect, and any regular noetherian local ring is a domain, hence has irreducible spectrum, and any open subset of an irreducible space is again irreducible, so the punctured spectrum is again irreducible.)
In the case that $U,V$ are both closed, you know that they must intersect inside the punctured spectrum - there's only one closed point and every closed subset contains it, so every pair of closed subsets must intersect. This lets us get at the problem for the punctured spectrum in much the same manner as we treat intersections in projective space via the affine cone. The same proof will apply here - I leave it to you to verify the details.
It is a fact that a (real or complex valued) continuous, or continuously differentiable, or smooth, or analytic, etc. function that vanishes nowhere has a multiplicative inverse in the same category. Moreover, by continuity, a function can only vanish on a closed set. Therefore the sheaf of such functions on a topological space has the property that its stalks are local rings. For irreducible algebraic varieties defined in the classical way we have rational functions, the sheaf of regular functions has the same property. For not necessarily irreducible algebraic varieties we can't really talk about rational functions but a closer analysis of the sheaf of regular functions on irreducible affine algebraic varieties reveals that it is not necessary to go via rational functions in the first place, and that is how we get to the definition of the structure sheaf of a general affine scheme. The fact that the stalks are local rings is, in some sense, incidental.
Let $k$ be an algebraically closed field and let $X$ be a subset of $k^n$. For the purposes of this answer, a regular function on $X$ is a function $f : X \to k$ for which there exist polynomials $p$ and $q$ over $k$ such that $q (x) \ne 0$ for all $x \in X$ and $f (x) = p (x) / q (x)$ for all $x \in X$. Let $\mathscr{O} (X)$ be the set of regular functions on $X$. Then:
If $X$ is an irreducible closed subset of $k^n$, then the assignment $U \mapsto \mathscr{O} (U)$, where $U$ varies over the open subsets of $X$, defines a subsheaf $\mathscr{O}_X$ of the sheaf of $k$-valued functions on $X$.
There is actually a claim to be checked here, namely that regularity of functions is a local property, but I leave that to you. The above definition required $X$ to be embedded in $k^n$, but this is actually unnecessary. Firstly:
If $X$ is a closed subset of $k^n$ and $f : X \to k$ is a regular function, then there is a polynomial $p$ over $k$ such that $f (x) = p (x)$ for all $x \in X$.
More generally:
Let $X$ be a closed subset of $k^n$, let $q$ be a polynomial over $k$, and let $U = \{ x \in X : q (x) \ne 0 \}$. If $f : U \to k$ is a regular function, then there exist a positive integer $m$ and a polynomial $p$ over $k$ such that $f (x) = p (x) / q (x)^m$ for all $x \in X$.
Moreover, if $U$ is dense in $X$, then the unique homomorphism $k [x_1, \ldots, x_n, u] \to \mathscr{O} (U)$ sending $x_1, \ldots, x_n$ to the respective coordinate functions $U \to k$ and $u$ to the regular function on $U$ defined by $1 / q$ has kernel $(I (X) + (q u - 1))$, where $I (X)$ is the ideal of polynomials vanishing on $X$.
Indeed, since $f : U \to k$ is a regular function, there exist polynomials $p_1$ and $q_1$ such that $q_1 (x) \ne 0$ for all $x \in U$ and $f (x) = p_1 (x) / q_1 (x)$ for all $x \in U$. By the Nullstellensatz, $\sqrt{I (X) + (q_1)} \supseteq \sqrt{I (X) + (q)}$; in particular, there exist a positive integer $m$ and $r \in k [x_1, \ldots, x_n]$ and $s \in I (X)$ such that $q_1 r + s = q^m$. Hence,
$$\frac{p_1 (x)}{q_1 (x)} = \frac{p_1 (x) r (x)}{q_1 (x) r (x)} = \frac{p_1 (x) r (x)}{q (x)^m}$$
for all $x \in U$, so we may take $p = p_1 r$.
Given a general element of $k [x_1, \ldots, x_n, u]$, say $p_0 + p_1 u + \cdots + p_m u^m$, where $p_0, \ldots, p_m$ are polynomials in $x_1, \ldots, x_n$ over $k$, we have
$$p_0 (x) + \frac{p_1 (x)}{q (x)} + \cdots + \frac{p_m (x)}{q (x)^m} = 0$$
for all $x \in U$ if and only if
$$p_0 (x) q (x)^m + p_1 (x) q (x)^{m - 1} + \cdots + p_m (x) = 0$$
for all $x \in U$. Since $U$ is dense in $X$, the second equation actually holds for all $x \in X$, so
$$p_0 q^m + p_1 q^{m - 1} + \cdots + p_m \in I (X)$$
and hence,
$$p_0 + p_1 u + \cdots + p_m u^m \in I (X) + (q u - 1)$$
as required. ■
The upshot of all this is that, if $X$ is an irreducible closed subset of $k^n$, then the sheaf $\mathscr{O}_X$ can be reconstructed from the ring $\mathscr{O} (X)$ together with the bijection between the maximal ideals of $\mathscr{O} (X)$ and the points of $X$: the above shows that, for a principal open subset $U \subseteq X$, i.e. $U = \{ x \in X : f (x) \ne 0 \}$ for some $f \in \mathscr{O} (X)$, the ring $\mathscr{O} (U)$ is the localisation of $\mathscr{O} (X)$ with respect to the multiplicative set $\{ 1, f, f^2, \ldots \}$. It is easy to check that the restriction maps are the obvious ones. Since the principal open subsets of $X$ form a basis for the topology of $X$, this determines the sheaf $\mathscr{O}_X$. Modulo the introduction of non-maximal prime ideals, this is exactly how one constructs the structure sheaf for a general affine scheme.
Best Answer
To expand on Bernard's answer, let $k$ be a field and consider the ring $R = k[[x^{\mathbb{R}_{\ge 0}}]]$ of formal power series of the form $\sum_{r \in S} c_r x^r$ where $r \in \mathbb{R}_{\ge 0}$ and $S \subseteq \mathbb{R}_{\ge 0}$ is well-ordered (this guarantees that multiplication is well-defined); these are known as Hahn series and they form a valuation ring.
For $f \in R$ a nonzero power series, write $\nu(f) \in \mathbb{R}_{\ge 0}$ for the smallest exponent of a nonzero term in $f$. If $I$ is any nonzero ideal of $R$, then if some nonzero $f \in I$ has valuation $\nu(f)$, then multiplying by every element of $R$, and observing that nonzero every $g \in R$ can be written as $x^{\nu(g)}$ times a unit, we see that $I$ contains every element of $R$ with valuation $\ge \nu(f)$. This means $I$ is determined by the valuations of its nonzero elements, and the set of all such valuations is an upward-closed subset of $\mathbb{R}_{\ge 0}$ (upward-closed means if $x \in S$ and $y \ge x$ then $y \in S$). There are two infinite families $[r, \infty)$ and $(r, \infty)$ of such subsets, so the ideals of $R$ come in two infinite families, namely
$$I_r = \{ f \in R : \nu(f) \ge r \}, r \in \mathbb{R}_{\ge 0}$$
and
$$J_r = \{ f \in R : \nu(f) > r \}, r \in \mathbb{R}_{\ge 0}$$
(together with the zero ideal, which you can think of as $I_{\infty}$). These ideals are totally ordered and in particular show that $R$ is very far from Noetherian. Note that $I_r = (x^r)$ is principal but $J_r$ is not even countably generated.
The corresponding quotients $R/I_r$ and $R/J_r$ contain nontrivial nilpotents, and hence $I_r$ and $J_r$ are not prime, except for $J_0$, which is the unique maximal ideal, and $I_0$, which is the unit ideal. So $R$ has exactly two prime ideals, $(0)$ and $J_0$, as desired.