In some normalized state |f> you want to know when is <f|AB|f>=<f|A|f><f|B|f> (if the state is not normalized, then we have to add some factors in the denominator, which is annoying notationally, but easy to do).
If A|f>=a|f> and B|f>=b|f> then we can see that <f|AB|f>=ba<f|f>=ab and <f|A|f><f|B|f>=ab<f|f><f|f>=ab. So in the case that |f> is an eigenstate of both A and B, then we will have this equality hold. This condition is therefore sufficient, but is it necessary? Actually it's late right now, and off the top of my head, I am unsure if this condition is necessary, perhaps you can finish the other half of the proof.
Do we need [A,B]=0? Well, in the above sufficiency argument we required that |f> be an eigenstate of both A and B. So we only required that the state in which we take the expectation value to be an eigenstate of both A and B. We did not require that A and B share a complete set of eigenstates. So although [A,B]=0 is a sufficient condition, since commuting operators share eigenstates, it is not strictly speaking necessary. There could be exotic conditions where non-commuting operators share 1 eigenstate in common for example.