Polynomials in a matrix and its commutant