Eternal vigilance is the price of liberty
The title of question asks for an AC improvement, but the OP says in comments "I had assumed that raising AC was the only solution. Please feel free to correct me." My answer will not touch on AC, but rather will focus on when and how a dragon moves, particularly Stealth and Perception.
The OP posits a "a single-accidental pass of a small yet well-hidden community of wood elves".
I take the 'accidental' and 'well-hidden' to mean that the dragon is flying over the elves without prior knowledge that they are there. Thus, the rules for Surprise are relevant.
From PHB: "Combat"
The GM determines who might be surprised. If neither side tries to be stealthy, they automatically notice each other. Otherwise, the GM compares the Dexterity (Stealth) checks of anyone Hiding with the passive Wisdom (Perception) score of each creature on the opposing side.
Any time the dragon needs to get somewhere, it should be choosing to fly at altitude - above darkvision range at night and, if possible, above bow range. Staying above where it can be targeted by missile weapons means its AC doesn't matter. If, for some reason, it is forced to fly near the ground, it should choose to move stealthily, repeatedly taking the Hide action any time it is within bowshot of the ground. Without stealth, the dragon and the elves will automatically notice each other, but if it is being stealthy, the dragon may escape notice. Even the youngest dragons have bonuses to Stealth and these improve as they age.
The wood-elf community, on the other hand, is stationary and its members are unlikely to be continually taking the Hide action 24/7 as they go about their lives - they would get nothing else done if they did so. Thus the dragon should likely notice the elves before they notice it and can then react accordingly.
If the dragon is flying at night when it hears the noise from the elven village and it is still outside of darkvision range, it could elect to simply continue on stealthily - with luck, its Stealth roll will beat the Passive Perception of every elf in the village and the active Perception rolls of their few sentinels, and it will be able to pass silently by. It should, of course, note the location of the village and remember not to fly accidentally above it again.
If the dragon is flying in the day (and the DM rules that Stealth is not possible while it is unobscured in plain sight) it will likely see the elves or their structures while still outside of bow range and can simply veer off and avoid the community altogether.
If for some reason (weather, terrain, darkness) the dragon is within bow range by the time it notices the community, it should immediately move outside of bow range (Dashing if that would take it out of normal range by the end of its move; if not, Dodging until it is out of normal range and then Dashing thereafter). Since the dragon was previously moving stealthily and at least some of the elves were not, it probably will be able to see them first, achieve surprise for many of them, and then extract itself from the situation before they can bring their numbers to bear.
A more challenging example would be a dedicated group of elven ambushers intentionally Hiding near where, for some reason, the dragon must pass at some point within bow range. Then, it is possible that the elves might be aware of the dragon's presence before it is of theirs and they might achieve surprise. Fortunately for the dragon, it has a good to great Perception and Passive Perception score and might have the Legendary Action Detect. Dragons should be difficult to surprise. The more ambushers there are, increasing the threat to the dragon, the more likely that at least one of them will get a Stealth score below the dragon's Passive Perception, and it will be warned.
Note 1: Some commenters have suggested that a larger number of ambushers would be more likely to surprise a dragon, when the DM permits a group check for Stealth, since the resulting value is more likely to be closer to the average. However, I believe that is a misapplication of the group check rules, which say (PHB 175) that they are "most useful when all the characters succeed or fail as a group." An ambush doesn't succeed or fail based on the whether all the elves are spotted or not - if the dragon spots any of the elves, then the ambush fails even if many or most of the elves are successfully hidden. Their success is thus determined by the single worst ambusher, not by the 'average' one and not by the total 'hiddenness'.]
Note 2: I do appreciate the time taken to do the combat calculations for ancient red dragons found in other answers. However, the OP specifically asked how dragons survive past eight centuries - so presumably they are interested in the younger age classes as well.