Noun:
* When it refers to a period of time: "He has been studying for many years."
* When it's used to express duration: "He spent years working on that project."
Adjective:
* When it describes something related to years: "The years-long project finally finished."
It's important to consider the context of the sentence to determine the correct part of speech.