How does one address a first officer in conversation? If I am just deplaning a commercial flight and I see the captain (4 bars on the epaulet) and want to thank him/her for a safe and enjoyable flight, I would say "Excuse me, Captain, thanks for the nice flight".

However, if I were to encounter the first officer (3 bars), how should I address him or her? "Excuse me, First Officer...?"

Presumably not "Hey co-pilot!" :)
Call the FO 'Captain' anyway.

Both crewmembers are equally rated in the aircraft.
The FO might have more time in the aircraft than the captain or even have been a captain at a previous airline, but is sitting in the right seat because of low seniority at this carrier.
Nobody minds being referred to by a higher title.
You're a passenger, no one expects you to be able to read the bars on their uniform anyway.