Emerton and Zoran's answers completely answer the question as stated, but there's another way to think about affine morphisms that is worth mentioning.
Given any quasi-compact and quasi-separated morphism of schemes $f:X\to Y$, $\newcommand{\O}{\mathcal O}f_*\O_X$ is a quasi-coherent sheaf of $\O_Y$-algebras. This functor has an adjoint, called relative $Spec_Y$, or relative Spec. Given a quasi-coherent sheaf of $\O_Y$-algebras $\newcommand{\A}{\mathcal A}\A$, we get a scheme over $Y$, $\phi^\A:Spec_Y \A\to Y$, with the property that $\phi^\A_*(\O_{Spec_Y \A})=\A$ and $Hom_Y(X,Spec_Y \A)\cong Hom_{\O_Y\text{-alg}}(\A,f_*\O_X)$ for any $f:X\to Y$. A morphism $f:X\to Y$ is affine if and only if $X\cong Spec_Y(\A)$ (as a $Y$-scheme) for some $\A$ (which must be $f_*\O_X$). See EGA II §1 for this development of affine morphisms.
I find this way of thinking about affine morphisms is useful for two reasons. First, if I'm working with a bunch of schemes affine over $Y$, it's often easier for me to think about a bunch of $\O_Y$-algebras with algebra morphisms between them. Second, the adjunction in the previous paragraph tells you that any (quasi-compact quasi-separated) morphism $f:X\to Y$ has a canonical factorization through an affine morphism $X\to Spec_Y(f_*\O_X)\to Y$, called the Stein factorization (the first morphism is Stein, meaning that the structure sheaf pushes forward to the structure sheaf). This factorization is often extremely handy; for example, if a morphism is quasi-affine, the Stein factorization is a witness of its quasi-affineness.