Animal pens, feed boxes, and even fighting around your base will not level animals. Only animals that follow you will gain experience.