Sorry about the mistake in the comment.  This is not true.  Let $S$ be $\mathbb{A}^2_k,$ the affine plane.  The open complement, $j:V\hookrightarrow \mathbb{A}^2_k,$ is a flat morphism, but it is not affine.  

Let $f:X\to S$ be the blowing up of $\mathbb{A}^2_k$ at the origin. This is a proper morphism. Denote by $E$ the exceptional divisor of $f$. Denote by $U$ the open complement of $E$.  As the complement of a Cartier divisor in a smooth scheme, the open immersion $i:U\hookrightarrow X$ is an affine morphism.  

Let $\rho:G\to X$ denote an $X$-scheme with two connected components, one of which maps isomorphically to $X$, $$\rho_e:G_e \xrightarrow{\cong} X,$$ and the second of which maps isomorphically to $U$, $$\rho_{\sigma}:G_{\sigma} \xrightarrow{\cong} U.$$  There is a unique structure of $X$-group scheme on $G$: the identity section is the inverse isomorphism of $\rho_e,$ and the multiplication morphism, $$G_\sigma\times_X G_\sigma \to G_e,$$ is the unique open immersion of $X$-schemes.  

The $X$-group scheme $G$ is flat and affine.  Yet the pushforward $\pi_*G$ is a disjoint union of a copy of $S$ and a copy of the open complement of the origin.  This open immersion is not affine.