Is anemia caused by an infection?

Can be. An infection can lead to some degree of anemia. The anemia should resolve with successful treatment of the infection.
Sometimes. Infections can cause anemia due to inflammation in the body which results in lowering of new blood cell production. Treatment consists of treating the infection and supporting the patients with blood transfusions & diet modificatins as needed.