I wrote up a Gym Guide for a friend of mine. So I thought I would share it. Feel free to correct anything that's wrong or add it to the OP if it's right.
The Basics:
Gyms have their own levels which and something called Prestige. Prestige contols the level of the gym, the level controls how many pokemon can be stored there. Gym levels can go up and down based on their prestige.
When it's your teams Gym:
When your team owns a gym you can train there. Training is 1 of your pokemon vs whatever is stored at the gym. The gym gains prestige for every pokemon you defeat and you gain experience. So you often train a gym that is already claimed by your team so you can increase the gym level and leave one of your pokemon.
Enemy Gyms:
If another team controls the gym you attack with a team of 6 to beat whatever is stored there. Every victory lowers the Prestige of the gym. As the prestige is lowered and the gym loses levels, the weakest pokemon drop off the gym.
Battle Strats:
You can brute force an enemy gym down. If you have the Potions and Revives to keep taking it on you can try over and over again. As long as you defeat a single pokemon the gym will lose prestige and eventually it will be your team of 6 vs 1 strong pokemon.
You can also use dodging to beat just about anything. Some battles would be crazy long if you aren't close in CP, but according to reddit you can win every match with enough patience. Dodge tutorial:
https://www.youtube.com/watch?v=HqSJhH6mVTQ
So why fight for a gym?
For every gym you capture and store a pokemon into you can claim a reward of 10 coins and some stardust. You can capture up to 5 gyms, giving you 50 coins. You decide when to claim the reward, but once it's claimed it goes on a 21 hour cool down.
So holding gyms for long periods isn't the goal. You're supposed to tear down and claim a few as close together as possible. You then claim your reward and do it over again the next day. Holding a gym for multiple days just means you don't need to claim if you are out capturing gyms.