Ring-theoretic characterization of open affines? Background
Recall that, given two commutative rings $A$ and $B$, the set of morphisms of rings $A\to B$ is in bijection with the set of morphisms of schemes $\mathrm{Spec}(B)\to\mathrm{Spec}(A)$.  Furthermore, we know that Spec$(A)$ has a base of open affine subsets, the "basic" or "principal" open affines $D(f)$ for all $f\in A$. Furthermore, $D(f)\cong \mathrm{Spec}(A_f)$ as schemes, and the inclusion $D(f)\hookrightarrow\mathrm{Spec}(A)$ corresponds to the localization map $A\to A_f$.
But answers to a recent MathOverflow question show that open affine subschemes of affine schemes can arise in other ways.

Question
In order to try to make sense of the situation above, I'd like to know the following.

Given a commutative ring $A$, is there a "ring-theoretic" characterization of the ring homomorphisms $A\to B$ that realize $\mathrm{Spec}(B)$ as an open affine subscheme of $\mathrm{Spec}(A)$ (more precisely, those morphisms such that the induced map $\mathrm{Spec}(B)\to\mathrm{Spec}(A)$ is an open immersion)?

Of course, "ring-theoretic" is a bit vague. Let's certainly avoid any tautological characterizations.  I would prefer if an answer didn't make any reference to the Zariski topology (for instance, the morphisms $A\to A_f$ make perfect sense without the Zariski topology), but I'm not sure whether that's reasonable.

Update: I received two great answers, thank you both!  I chose the one that was closer to the kind of condition that I had in mind.  But Dan Petersen's answer was also very interesting and unexpected.
 A: There is the following characterisation. I don't think it's too tautological. Let $T \subseteq A$ be the set of f such that the induced map $A[f^{-1}] \to B[f^{-1}]$ is an isomorphism. Then $\mathrm{Spec}(B) \to \mathrm{Spec}(A)$ is an open immersion if and only if the image of $T$ in $B$ generates the unit ideal. 
A: Theorem 1: Let $R$ be an integral domain with field of fractions $K$, and $R \to A$ a homomorphism. Then $Spec(A) \to Spec(R)$ is an open immersion if and only if $A=0$ or $R \to K$ factors through $R \to A$ (i.e. $A$ is birational over $R$) and $A$ is flat and of finite type over $R$.
Proof: Assume $Spec(A) \to Spec(R)$ is an open immersion and $A \neq 0$. It is known that open immersions are flat and of finite type. Thus the same is true vor $R \to A$. Now $R \to K$ is injective, thus also $A \to A \otimes_R K$. In particular, $A \otimes_R K \neq 0$. Open immersions are stable under base change, so that $Spec(A \otimes_R K) \to Spec(K)$ is an open immersion. But since $Spec(K)$ has only one element and $Spec(A \otimes_R K)$ is non-empty, it has to be an isomorphism, i.e. $K \to A \otimes_R K$ is an isomorphism. Now $R \to A \to A \otimes_R K \cong K$ is the desired factorization.
Of course, the converse is not as trivial. It is proven in the paper

Susumu Oda, On finitely generated birational flat extensions of integral domains
  Annales mathématiques Blaise Pascal, 11 no. 1 (2004), p. 35-40

It is available online. In the section "Added in Proof." you can find some theorems concerning the general case without integral domains. In particular, it is remarked that in E.G.A. it is shown that
Theorem 2: $Spec(A) \to Spec(R)$ is an open immersion if and only if $R \to A$ is flat, of finite presentation and an epimorphism in the category of rings.
More generally, in EGA IV, 17.9.1 it is proven that a morphism of schemes is an open immersion if and only if it is flat, a (categorical) monomorphism and locally of finite presentation.
There are several descriptions of epimorphisms of rings (they don't have to be surjective), see this MO-question.
