Single-electron and Cooper-pair tunneling in systems of small junctions coupled to an electromagnetic environment