“A year” is grammatically correct. “A“ is the correct article to use with the word “year”. “An year” is incorrect and should not be used in English.
I lived in Rome for a year.
I studied piano for a year or two.
Why is it A year and not An year?
We use “an” with vowel sounds and “a” with consonant sounds.
The word year starts with a consonant sound (j) similar to words like user, young and yacht.
Remember it is not the first letter that determines if we use “a” or “an”, it is the sound.
Usually, words that begin with a “y” have a (j) sound and therefore use the article “a”.
I want to spend a year in Japan learning Japanese.
I want to buy a yacht when I am rich.
When I was a young boy, things were much easier.