Can a gym get free without battling?
The only way to remove Pokemon and in turn a team from a gym is by lowering the Prestige of the gym down to zero. Every time you defeat a single Pokemon in the gym, it lowers the prestige by a little bit, with a bonus for defeating every Pokemon in the gym.
To answer your second question, yes, a gym can theoretically be held forever by a single team if no one decides to fight it.