we usually say if you can take care of them you can keep them. Cavities are not a good indication of care.
Some dentists will not fill third molars. Seek a second opinion on restoring these teeth. It may be that they are also beyond repair.
Although the rate of complication is higher when you are older, teeth can be extracted at any age safely.