Arduino mega or shift register for 40 LEDs all on/off or individually on/off

If you only need to control the LEDs in 4 blocks (i.e. all the LEDs in each block of 10 always do the same thing), then the simplest solution is just to use 4 of the PWM-capable output pins of an Arduino, each one driving a BC337 transistor through a 470 ohm resistor, and connect 10 LEDs (each with a series resistor) between your +ve supply and the collector of each transistor. If your +ve supply voltage is high enough, you may be able to connect 2 or more LEDs in series with each resistor, saving on current and series resistors. You don't need a Mega for this, a Uno will do.