Voice of experience here . . . I am on my third boat in salt water having run & kept boats in salt water for the past 20 years.
There are 2 things going on with salt water (that is more so than fresh water)
There is galvanic corrosion
and there is rust
First Galvanic Corrosion:
The outdrives are made of aluminum, steel, and stainless stainless steel. When submerged in water (and particularly salt water) Galvanic corrosion, also known as bimetallic corrosion, is an electro-chemical process where two dissimilar metals in contact with each other corrode at different rates in the presence of an electrolyte, such as saltwater or moisture.
The least strong metal of the 3 is aluminum and the strongest is stainless steel. So, to prevent the stainless steel from taking all the electrons from the aluminum, a 4th metal is introduced . . . known as the anode. It is a weaker metal than the aluminum of the outdrive and therefore 'sacrifices' itself to the 3 'stronger' metals (aluminum, steel, stainless steel). I usually get about 3 months life of anodes in salt water. Then they need to be replaced.
You asked about the engines . . . (Rust)
The engines are iron/steel . . . The nature of the design, water is retained within the engine, even when not in use. Rust is a specific type of corrosion that occurs when iron or its alloys (like steel) are exposed to oxygen and moisture, forming iron oxide. Anodes won't really help against oxidation.
'Raw water cooled' engines are highly susceptible to rust/scaling in salt water which is more aggressive than fresh water. Closed cooling systems have been a way of keeping raw water out of the engine (at least most of it).
My first powerboat was raw water cooled and after about 20 years of salt water, enough metal had flaked off the internals of the engine block, cylinder heads, manifolds, etc. that it was no longer viable.
My next 2 boats were closed cooling (one of them being run in fresh water for 15+ years and then having closed cooling added before running in salt water for another 10+ years). My third powerboat had closed cooling from the factory (Mercruiser SeaCore)
So, in salt water and even fresh water, you are going to need to protect the outdrive(s) from galvanic corrosion (anodes). The engines can deal with fresh water and last for quite some time. In salt water, and raw water cooled, the engines are going to last 15-20 years. Flushing the engine may help, but it is not a panacea. Exposure to salt water will still promote rust and scaling within the engine.
The newer engines have catalytic converters in the exhaust (know as CAT engines), Replacing the exhaust on these engines is wicked expensive, although the exhaust systems of late seem to be more robust. Every 5 years might be quick, but boat shops like to keep the revenue flowing.
Share with us the details of the boat you are thinking of buying and folks can add more specific comments.