McGonagall was unhappy at the Ministry and when offered a big promotion, she instead sent an owl to Hogwarts asking if she might be considered for a position at the school. She was offered a post and took it immediately.
There is a contradiction between Rowling's statement during an interview that McGonagall was "a spritely seventy" in 1995 and her informing Umbridge during 1996 that she had been teaching at Hogwarts for thirty-nine years in December. If she was in fact 70 years old in 1995, she would have been teaching at Hogwarts for forty-nine years, not thirty-nine.
It is possible that she was telling Umbridge that she had held the position of head Transfiguration teacher for thirty-nine years, which would coincide with Dumbledore taking over as Headmaster of Hogwarts, or she was deliberately subtracting ten years from her service. Both explanations are a stretch, especially the idea that she would in any way minimize her level of experience when talking to Umbridge. The other explanation is that Rowling's comment that McGonagall was seventy years old was incorrect. This seems the most likely, given her self-admitted poor math skills.