Sure you can! Render the flag (with alpha) and the background separately, as an image sequence, then composite them together using the Video Sequence Editor.
If the flag casts a shadow on the ground, you may need to do an additional pass for just the ground shadow. To do that I make a “shadeless” white shader for all of the shadow casting objects, and a white shader for the ground with 0.5 emit (this softens the shadow a bit). You can also use “Only Shadow” but it gives really crude results, and I haven’t found a way to fix that. Then multiply that layer into the final comp.
Here is a video I made which uses compositing fairly heavily. There were about 13 layers of compositing in all. It’s not uncommon for big budget productions to have more than that. Here are some breakdown shots from X-Men for example.