Let $S=\\{t[x_1,\dots,x_n] : t\text{ is a term of $L$ and }x_1,\dots,x_n\in X\\}$. Clearly any submodel $C$ of $A$ that contains $X$ must also contain $S$, since every element of $S$ is obtained by repeatedly applying operations starting from elements of $X$ and $C$ must be closed under the operations. (More formally, you can prove by induction on terms that each element of $S$ is in $C$.) So, $S\subseteq B$.
To prove the reverse inclusion, simply observe that $S$ itself is a submodel of $A$: it is closed under all the operations since if you apply an operation to some terms you just get a bigger term using the function symbol corresponding to the operation. So $S$ is a submodel of $A$ that contains $X$, $B\subseteq S$.