"I have been working on it for five months."
Translation:Pracuji na tom pět měsíců.
I think that měsíců is in the genitive because that's how you use numbers 5 and above (Tips and Notes https://www.duolingo.com/skill/cs/Numbers-2 and this also talks about the cases used with some prepositions) but pět and the whole noun phrase is either nominative or accusative ( https://en.wiktionary.org/wiki/p%C4%9Bt ) but I'm not sure which. The wiktionary articles for prepositions 'na' ( https://en.wiktionary.org/wiki/na#Czech ) and 'v' ( https://en.wiktionary.org/wiki/v#Czech ) talk about when they take which case.
This discussion is why měsíců is gentive. The reason is that all numbers above four work that way.
About the na + locative:
This is really just a phrase you should learn. "work on something"="pracovat na něčem"
We are lucky that the English "on" coincides with the Czech "na", but it is just a coincidence. Na generally takes accusative or locative. And it is the locative that is used here and you must learn that.
"I have been working" is not a past tense, it's the present perfect tense. The work began five months ago and is likely not even finished now, it's still in progress. Czech prefers to use the present tense here.
If the work had begun, e.g. 7 months ago and ended 2 months ago, we would use the past tense in both languages: I worked on it for 5 months. Pracoval jsem na tom 5 měsíců.
There is a borderline case though where if I have just completed the work now, I might use the present perfect in English but the past tense in Czech.