As with many questions of this kind, both answers are acceptable although the second is more likely.
The issue is whether the speaker considers the two years as the period spent in the place or as individual units.
So it's perfectly legitimate to write either:
I spent two days on the island and it nearly killed me.
Here the writer uses it to emphasise the dreadful experience he/she endured.
I spent two days on the island and they nearly killed me.
In this instance, the writer is emphasising the days spent on the island.
The same reasoning applies to your examples. Whether you opt for singular or plural depends largely on the context and whether you consider the days/years concerned - as single period or as individual time units.