orbiting around a moving object(moon&earth)
Select your earth, and add an empty at the same position. Hold shift, and select the earth. Enter edit mode. While editing the earth's mesh, add a vertex at the center of the earth. Press Ctrl+P and select make vertex parent. Now, the empty will have the same location of the earth, but will be able to rotate independently of the earth's rotation. Parent the moon to that empty. Now, you can animate the empty rotating to make the moon's orbit. Do the same thing with the sun. Add an empty at the sun's position, add a vertex in the center of the sun, create a vertex parent of that empty. Then, parent the earth to that empty. you can animate the empty on the sun to create the earth's orbit around the sun, and the moon's orbit will remain consistent.