Many swimming microorganisms, such as bacteria and sperm, use flexible flagella to move through viscoelastic media in their natural environments. In this paper we address the effects a viscoelastic fluid has on the motion and beating patterns of elastic filaments. We treat both a passive filament which is actuated at one end, and an active filament with bending forces arising from internal motors distributed along its length. We describe how viscoelasticity modifies the hydrodynamic forces exerted on the filaments, and how these modified forces affect the beating patterns. We show how high viscosity of purely viscous or viscoelastic solutions can lead to the experimentally observed beating patterns of sperm flagella, in which motion is concentrated at the distal end of the flagella.