Invincibility in LEGO Batman is available as an extra that you can purchase for 500,000 points, but first you'll need to unlock it. To do so, find the corresponding red brick during free play. It's located within the mission titled Dying of Laughter, which is the final villain level, the fifth chapter in the Joker sequence, set at Gotham Cathedral. Climb the spiral staircase on the stage right, then destroy the chandelier with a bat-a-rang. Use the pieces from the broken chandelier to build a floor sweeper, then clean up all the peanut butter and jelly paint on the floor. Once that's done, the red brick will appear.
Alternatively, if you'd rather take the shortcut, you can simply enter the following cheat code:
Invincibility WYD5CP