Yes, as the other answer notes, B has distinct eigenvalues. Therefore, anything commuting with it must be a polynomial in B. (Degrees no higher than 2 suffice.)
In some detail: let T be a matrix so that $TBT^{-1}$ is diagonal, with distinct diagonal entries $b_1, b_2, b_3$. Since $AB=BA$, $(TAT^{-1})(TBT^{-1})=(TBT^{-1})(TAT^{-1})$. For any matrix $M$, the $ij$ entry of $M(TBT^{-1})$ is $m_{ij}b_j$, while the $ij$ entry of $(TBT^{-1})M$ is $b_im_{ij}$. Thus, a matrix commuting with $TBT^{-1}$ is diagonal. Use Lagrange interpolation to find a quadratic polynomial $P$ so that $P(TBT^{-1})=TAT^{-1}$ is that other polynomial. Happily, $P(TBT^{-1})=T.P(B).T^{-1}$, so $A=P(B)$.