If you haven't already read it, an excellent book to study after Hartshorne, which moves in the direction you are interested in, is Mumford's Lectures on curves an algebraic surface. In this text, Mumford doesn't go as far as defining the moduli space of curves; rather, he studies families of curves on a given surface. But in doing so, he introduces (with complete proofs of their existence) Hilbert schemes and Picard schemes, which are basic tools in the rigorous study of moduli problems.
Another very nice Mumford text (an article this time, not a whole book) is Picard groups of moduli problems. This is the first place that the moduli stack of genus $g$ curves appears (although it is not so named in this paper). You could combine this with the famous paper of Deligne and Mumford on irreducibility of the moduli of curves, to get an introduction to the subject.
I haven't read Hartshorne's deformation theory notes, but I imagine that the above mentioned texts would make a good complement to them. (In case you haven't read anything by Mumford, it is worth mentioning that he is one of the great expositors as well as one of the great geometers, which is why I am so enthusiastic in recommending his writings!)