За + <time period in Accusative> and на + <time period in Prepositional> sometimes can be interchangeable depending on the context, but not always.

Namely "за" construction is OK when you speak about completed actions (and use perfective verbs).

"На" construction is more tricky. It can be used with both perfective and imperfective but is applicable only for some words of time periods. For example one can say "на прошлой неделе" but never "на прошлом месяце". Also often it makes style colloquial or gives some unusual and specific meanings. It is not safe to use.

за каникулы <-> на каникулах

На каникулах я отдохну. = За каникулы я отдохну. This is almost the same. "I'll complete my rest on vacations."
На каникулах я буду отдыхать. "I'll have some rest on vacations." За construction will not work here.

на последнем году <-> за последний год
This is not the same.
Here is a specificity. "на последнем году" means basically "during someone's last (final) year of life". It is a kind of set phrase.
"за последний год" will work if you make a report of what has been done during the previous year.

Also one can say that "на" construction makes logic accent on the time period against other time periods while "за" construction makes logic accent on the actions completed during the time period.