an can mean many things (the, their, does…?, is…?, and others depending on context), and it also can just mean in.
In this case the whole ann an means ‘in’ – it comes from doubling the an(n) in preposition, possibly to avoid confusion with the article (the an meaning the). So whenever you see ann an, it generally just means in with no definite article in there.
Before the article, the preposition an(n) changes to anns and is not doubled, so in the school is anns an sgoil (sometimes shortened to san sgoil) – here the second an (or just the an part in shortened san) is the article.
For a much longer explanation see this article on the Akerbeltz wiki.
It all makes so much more sense now that I have found the light bulbs. No wonder I was struggling so much. I couldn't understand how we were supposed to learn the rules if they were never explained. Any chance the light bulbs could make it onto the android app one day? Or at least a mention that they are on the website to save anyone else all the confusion?