When I first read the sentence, I automatically placed "a" in the first gap. Both "a" and "the" are possible for the first one, but the meaning of the sentence with "the" is a bit unusual. If I chose "a", I would place a comma before "with...". It's a slightly bad example for a question, unfortunately.
"the best teacher" - there can be only one, unique "best" teacher.
Always: the + superlative adj. + noun
"the school" because the sentence implies that the reader is familiar with Terry, and the fact that he teaches at a particular school. We can imagine that the previous sentences were: "Terry worked for many years as a teacher at St Trinian's School. One day, he took an exam to become an excellent teacher......."