While your companions idle, they will gain a small fraction of experience.
But, once you get the Stronghold unlocked, they will idle there and can eventually (with the proper upgrade to the Stronghold) go on their own side adventures which will grant them additional experience, items, money and even give your party reputation boosts. You can check in on your idle party members to see what they are up to at any given time.
I would recommend going back and exchanging 1-for-1 party member each time you level if you care enough. It is unlikely that the idle members are going to level at the same rate as your main group, so they will still be short of a level. You can finish their level off and more importantly you will be the one selecting their talents and skills for the level-up. If they level while you aren't in control they will choose their own and will often derail any plans you may have had for them or just in general pick some awful options.