Categorical construction of the category of schemes? The answer to the following question is probably well known or the question itself is well known not to have a reasonable answer. In the latter case could you please let me know what the "right" question may be (rather then stating that the answer is 42;))
Is there a purely categorical procedure that takes the category of commutative rings as input and produces the category of schemes (over $\mathbf{Z}$) as output?
A possible place to start would be to consider a scheme $X$ as a functor from the category $CommRing$ of commutative rings to the category of sets: $A\mapsto Hom_{Sch}(Spec(A),X)$ where $A$ a commutative ring. If we instead of $Spec(A)$'s we consider all schemes, then we simply get the Yoneda embedding. But some questions arise.


*

*Does this give a fully faithful functor from schemes to functors from commutative rings to sets? Or loosely speaking, do $Spec(A)$-valued points ($A$ a commutative ring) suffice to determine a scheme? (My guess is that the answer is yes and this is classical.)

*Is there a way to characterize those functors that actually come from schemes? For example one can introduce a Grothendieck topology on $CommRing$ (or its opposite) and require that the functor should be a sheaf in that topology. But in that case, can one describe the topology without referring to the fact that the objects of $CommRing$ are commutative rings? (Here my guess is the first question is probably too complicated but there are some necessary conditions.)

*Regardless whether the answer to 2. is positive or negative, is there a way to describe algebraic spaces or stacks as presheaves on $CommRing^{op}$ that satisfy some conditions?
 A: If $B$ is a site, then the presheaf category $\hat{B} = Set^{B^{op}}$ is also a site and the topology restricts to the one on $B$. See this related question.
If we take $B$ to be the dual of the category of rings with the Zariski topology ($R_i \to R$ is a covering iff the ring morphisms $R \to R_i$ are localizations at elements $f_i \in R$ such that the $f_i$ generate the unit ideal), consider the full subcategory of $\hat{B}$ consisting of all sheaves which are covered by representable functors, then we get the category of schemes with the Zariski topology.
Also if $B$ is the category of open subsets in some euclidean space, you can produce the category of manifolds.
Basically, this constructions allows you to construct global objects using local models.
A: It's worth pointing out Zhen Lin Low's thesis

Low, Z. L. (2016). Categories of spaces built from local models (doctoral thesis). doi:10.17863/CAM.384

with abstract

Many of the classes of objects studied in geometry are defined by first choosing a class of nice spaces and then allowing oneself to glue these local models together to construct more general spaces. The most well-known examples are manifolds and schemes. The main purpose of this thesis is to give a unified account of this procedure of constructing a category of spaces built from local models and to study the general properties of such categories of spaces. The theory developed here will be illustrated with reference to examples, including the aforementioned manifolds and schemes. For concreteness, consider the passage from commutative rings to schemes. There are three main steps: first, one identifies a distinguished class of ring homomorphisms corresponding to open immersions of schemes; second, one defines the notion of an open covering in terms of these distinguished homomorphisms; and finally, one embeds the opposite of the category of commutative rings in an ambient category in which one can glue (the formal duals of) commutative rings along (the formal duals of) distinguished homomorphisms. Traditionally, the ambient category is taken to be the category of locally ringed spaces, but following Grothendieck, one could equally well work in the category of sheaves for the large Zariski site—this is the so-called ‘functor of points approach’. A third option, related to the exact completion of a category, is described in this thesis. The main result can be summarised thus: categories of spaces built from local models are extensive categories with a class of distinguished morphisms, subject to various stability axioms, such that certain equivalence relations (defined relative to the class of distinguished morphisms) have pullback-stable quotients; moreover, this construction is functorial and has a universal property.

That last sentence is perhaps stronger than other answers here, which in all likelihood give the construction that Zhen Lin does, albeit in the special case of only schemes.
A: *

*The highbrow way of reformulating your question is as follows. Consider the category $Sch$ of all schemes endowed with the Zariski topology. There is a fully faithful embedding of the category of affine schemes $Aff = CommRing^{op}$ into $Sch$; the topology induced on $Aff$ by that on $Sch$ is also the Zariski topology. The comparison lemma ([SGA4] III, 4.1) then says that, because any object in $Sch$ can be covered by objects in $Aff$, the categories of sheaves on both sites are equivalent. In particular, representable sheaves in $Sch$ (i.e., schemes) are determined by their values on affine schemes.

*For a sheaf $F$ on $Aff$ to be represented by a scheme it is enough that it be covered by affine schemes, i.e., that there exist affine schemes $U_i$ together with open immersions $U_i \to F$ (you have to define what this means, of course) such that $\coprod_i h_{U_i} \to F$ is an epimorphism of sheaves. Actually, you can take this as a definition of schemes. The compatibility of the gluings in the classical definition is taken care of here by the sheaf condition.

*Algebraic spaces can be similarly defined. While I was writing this, Harry beat me to giving the reference to the excellent notes of Bertrand Toën from a course of his on algebraic stacks.


In 2, you also ask if you can construct schemes from $Aff$ without actually using the fact that you are dealing with commutative rings. I think not. The categorical nonsense can get you only so far: at some point you have to introduce the geometry itself, and that is given by the $Aff$ with its topology. If you replace $Aff$ by the category of open sets in some $\mathbb{R}^n$ with open immersions you would end up defining manifolds. This is what Toën calls geometric contexts.
A: The answer to the main question is undoubtedly "yes". I think there are going to be two lots of literature about this, one coming direct from the Grothendieck school (probably somewhere in the Demazure-Gabriel book), and another from the category-theorists, where I remember some work of Cole that puts the construction in a more general context. (I'm lying when I say "I remember"; I was certainly told about this at one point and filed away the information mentally.) I think the answer to Q1 is "yes and foundational", to Q2 is that representable functors are so well studied that the information is available, but being a scheme is rather subtle in practical terms. The connection with the flat topology here is well known.
As for Q3, even more out of my depth here.
A: The answer to 1. is yes. The answer to 2.) is also yes. Look here: http://rigtriv.wordpress.com/2008/07/16/representable-functors/
For 3.) A "strong" algebraic (Artin) stack is a "geometric stack" on the category of affine schemes=opposite category of commutative rings equipped with the etale topology. http://ncatlab.org/nlab/show/geometric+stack. In other words, it a pseudofunctor (or fibred category) obtained by stackifying a strict 2-functor of the form $Hom(blank,G)$, where $G$ is a groupoid object in schemes (so technically to view these as geometric stacks, you should take your site to be all schemes, not just affine ones). There are some subtleties however:
*You need that the source and target map of the groupoid $G$ are smooth maps of schemes.
** Often, Artin stack means instead the stack associated to a groupoid object in algebraic spaces, rather than schemes.
A: What you ask is just the way of doing scheme theory in 

Demazure and Gabriel, Introduction to algebraic geometry and algebraic groups. Translated from the French by J. Bell. North-Holland Mathematics Studies, 39. North-Holland Publishing Co., Amsterdam-New York, 1980 (Google Books, MR563524, zbMATH)

A: Toen's notes on stacks construct the category of schemes as the category of etale sheaves (presheaves satisfying descent in the etale topology) on CRing^op with a jointly surjective cover by smooth monomorphisms (exercise: show that smooth monomorphisms of affines are etale) of representable functors (i.e. affines).  
https://ncatlab.org/nlab/show/Master+course+on+algebraic+stacks
He constructs algebraic spaces in a similar way, then constructs algebraic stacks using the same approach after a digression into homotopical descent theory (which generalizes readily to the approach taken in Toen-Vezzosi (Homotopical Algebraic Geometry).  
The case of schemes is given a more general treatment in a fixed "geometric context", which is a category with a grothendieck topology and a fixed class of morphisms compatible with it.  A scheme is then simply a "geometric variety" in the "algebro-geometric context", which is CRing^op equipped with the etale topology, where the fixed class of morphisms is the class of smooth morphisms of affines (morphisms corresponding to smooth morphisms in CRing).  
