Necessary and sufficient conditions mean we're looking for some condition(s) $P$ such that
Condition $P$ begin satisfied implies that such an $f\in S$ exists. Conversely, if such an $f\in S$ exists, then condition $P$ is satisfied.
You might know this as an "if and only if" statement. For this particular problem, we must find out what "condition $P$" is. Let's look into it.
First suppose our cherished $f$ exists. Since $f$ has the property that $f$ maps zero to itself and $f(D)=D$, the Schwarz lemma applies (as you said). However, recall there is another condition in addition to $|f(z)|\leq |z|$: that $|f'(0)|\leq 1$. Therefore it must be the case that $|b|\leq 1$.
The above discussion gives us a candidate for a "condition P". In fact, we have just shown the $(\Leftarrow)$ direction; we just need make sure we don't need to add anything to this condition in order to prove the converse direction--but this shouldn't be very difficult to show: after all, the function $h(z)=bz$ maps $D$ to itself (because $|b|\leq 1$), has the property that $h(0)=0$, and $h'\equiv b$. In particular, $h'(0)=0$, so we know such a function exists when we're given a $|b|\leq 1$. This shows the $(\Rightarrow)$ direction.
Lastly, there's the matter of describing all functions in $S$ having the properties you've stated. As you've noted, any $f: D\to\overline{D}$ with $f(0)=0$ can be written as (setting $a=0$)
$$
f(z)=zg(z)
$$
where $g\in S$ (while this expression seems true, I'm taking your word/your teacher's word for it here). We compute
$$
f'(z)=g(z)+zg'(z).
$$
So
$$
f'(0)=g(0)+0g'(0)=g(0).
$$
Since we desire $f'(0)=b$, it follows that we need $g(0)=b$. Therefore
$$
g(z)=\frac{b+z\tilde{g}(z)}{1+z\overline{b}\tilde{g}(z)}
$$
for some other $\tilde{g}\in S$. Furthermore
$$
f(z)=z\left(\frac{b+z\tilde{g}(z)}{1+z\overline{b}\tilde{g}(z)}\right).
$$
From our discussion, the full statement should be
An $f\in S$ exists such that $f(0)=0$ and $f'(0)=b$ if and only if $|b|\leq 1$.
Hopefully this helps.