Neutrino flavor oscillations and spin rotation in matter and electromagnetic field