How to display only the years that have content in view filter?
If you go to views page (/admin/structure/views), you will find a view "Archive", you can clone it and use it, it will be displaying content month+year using contextual filter "Content: Created year + month", as you want to display only year, use contextual filter ""Content: Created year" and remove "Content: Created year + month".

Screenshot for contextual filter.



Screenshot of output.



It will list all the years that have content added.

Update

What you can do is to create a block of the view, and place it on the page you want, and then when you will click on an year, you can have the content list accordingly on the same page.