First, based on the ONI, there are El Niño and La Niña periods, not necessarily years. For example, 2016 was El Niño during the first half and La Niña during the second half. On the flip side, From summer 1998 to early 2001 was one continuous La Niña period.
Second, The The wording that the NOAA gives for official classification of El Niño and La Niña periods is a bit misleading. El Niño periods are designated as such when there are 5 consecutive three-month-running means of sea surface temperatures that are 0.5 degrees C above the 30 year mean. For example, take a look at NOAA's ONI data here: https://origin.cpc.ncep.noaa.gov/products/analysis_monitoring/ensostuff/ONI_v5.php
in 2016 there was an La Niña event that lasted from July to January because there were 5 three-month-running means in a row that were 0.5 degrees C below the 30 year mean. However, this only encompasses three "season", summer, fall, and winter.
Third, to answer your question, El Niño/La Niña classification is not bound by a calendar year, so going forwards and backwards until you hit a three-month-running mean that is less than the 0.5 threshold. The NOAA has already down the work for you, and even color coded it for you at the link above. Hope this helps.