Let $f:X \to Y$ be a morphism of schemes. It is called affine if there exist a covering $\{U_{\alpha}\}_{\alpha}$ by open affine $U_{\alpha}$ such that every $f^{-1}(U_{\alpha}$ is affine.
My question is why this property already indeces that for every open affine $U \subset Y$ the preimage $f^{-1}(U)$ is affine?
Indeed thats clear to me that that's enough to consider the case that $Y:=Spec(R)$ is affine (because by def for every open affine $U$ the restricted map $f: f^{-1}(U) \to U$ is affine). Futhermore, we can find $r_1, ..., r_i \in R$ such that $Y= \bigcup D(r_j)$ where $D(r_j)$ are open affine, such that $X = \bigcup f^{-1}(D(r_j))=\bigcup D(f^*(r_j))$ is covered by open affine $ f^{-1}(D(r_j))=D(f^*(r_j))$. But that's not clear to me how I can deduce from this that $X$ is affine, therefore $X = Spec(\mathcal{O}_X(X)$.
Let us do $i=2$ first. We have $R\to S=\mathcal{O}_X$ the natural map. You are given $f^{-1}(D(r_i))= \mathrm{Spec}(A_i)$. So, you have natural maps $S\to A_i$ and thus $A_i\to A_{ij}$ where $A_{ij}=A_{ir_j}=A_{jr_j}$. Easy to check that if $f_i\in A_i$ such that $f_i=f_j$ in $A_{ij}$, then there exists an $f\in S$ such that $f\mapsto f_i\in A_i$. Now, let $p\in A_1$. Then $r_1^n p=q\in A_{ij}$ for some $n\in\mathbb{N}$ and $q\in A_j$. Thus,, we see that there is an $f\in S$ such that $f\mapsto r_i^n p\in A_1$. This shows that $S_{r_1}=A_1$ and similarly for $r_2$. Then, it is easy to check that $X=\mathrm{Spec}\, S$, using the fact that $Sr_1+Sr_2=S$.
Now to do three (other cases should be clear), write $ar_1+br_2+cr_3=1$ in $A$. Then, let $s=ar_1+br_2$. Now, $f^{-1}(D(s))$ is affine, by the two case since $r_1, r_2$ generate the unit ideal in $A_s$. Since $s, r_3$ generate the unit ideal in $A$, again the two case does what you want.