We may assume $f$ is monic (if not, divide by its leading coefficient). As you say, it is enough to show that $Q(B)[x] f \cap B[x] = B[x]f$. The trick to prove this is to use polynomial long division: we can test whether a polynomial $g$ is divisible by $f$ by performing the division algorithm and seeing whether the remainder is $0$. Note that since $f$ is monic, the division algorithm never involves division of coefficients (just subtraction and multiplication), so it can be performed in the ring $B[x]$ and will produce a quotient and remainder which still have coefficients in $B$. So, if $g\in Q(B)[x] f\cap B[x]$, the remainder when we divide $g$ by $f$ is $0$, but the quotient is in $B[x]$ since $g\in B[x]$, proving that $g\in B[x]f$.
Another perspective on this is that for any $K$-algebra $B$, the quotient $B[x]/f$ is a free $B$-module on $1,x,x^2,\dots,x^{n-1}$ where $n=\deg f$ (this again follows from polynomial division, since these powers of $x$ span the possible remainders you can get when dividing by $f$). This makes it clear that if $B$ is a subalgebra of $C$, then $B[x]/f$ embeds in $C[x]/f$, since you can just extend the scalars to $C$ using the same basis. (Or in fancier language, $K[x]/f$ is flat over $K$, so we can tensor the inclusion $B\to C$ with $K[x]/f$ to get an injection from $B\otimes_K K[x]/f\cong B[x]/f$ to $C\otimes_K K[x]/f\cong C[x]/f$.)