If you lose your medical, hopefully you have some sort of disability insurance or loss of medical insurance. Many smaller companies do not have this but bigger companies do.
My last employer and current employer would often find jobs in the training department for pilots that lose their medicals, and they can teach in the simulator or ground school, or do office work such as develop manuals or training materials.
If you fail your annual check, you usually get additional training and a recheck, but if you continue to have problems then you get fired usually.
Most companies allow a pilot to stay an FO forever but some have forced upgrades. Some companies have an up or out policy, where you get fired if you fail upgrade, so I guess the answer is it depends on the company.