- Is it allowed by the rules to change the team formation during a match?
- Does it happen often when a coach decides to swap players between positions?
- Does it happen often when a coach decides to change team formation?
The rules actually don't say anything about formations. The only thing they say is that there are 11 players per side - one of which is designated a goalkeeper, and that if a team drops below 7 players the match cannot start/continue (source: IFAB Law 3: The Players.)
Formations are all about strategy. If the team is playing an attacking strategy, they will play more players up - formations like 4-3-3 or 4-5-1. A more defensive formation would be something like 5-3-2 or 4-1-4-1. These would put more players in the backfield.
However, there's nothing that restricts players to certain areas of the field based on their formation. You'll almost always see one or more midfielders help out on attacks, but you will sometimes see defenders come up to help as well. Defenders can be playing higher than midfielders (or even forwards) for a time, though they will usually return to the backfield - not because the rules say they have to but because in a formation it's good to be where you're supposed to be so your teammates can be where they're supposed to be.
So, to answer your specific questions:
EDIT: I've known people to ask about the formation that the sportscasters usually announce before the game, so here are some notes on that. I do not have citations for these, they're just what I believe to be true.
Although a formation is not required by the rules, it is often possible to tell what a formation will look like by examining the players that will be on the field. Some players are generally attackers, some defenders, and some midfielders. You can also sometimes tell based on knowledge about the coach - what formations has s/he used in the past in different situations.
Lastly, I believe that coaches sometimes will mention the formation they're using when announcing the starting line-up. This is not required, though.
Best source I have for this is another stackexchange post.
Players can change formations/positions at any time, mostly at the coaches discretion. For example, if you are winning you may want to play more defensively to protect your lead and if you are losing then you many want to be more attacking minded.
Changing positions/formations happens quite often but it all depends on the opposition.