Miniature Traffic Light with Raspberry Pi: Wiring many LEDs
Are you familiar with shift registers like 74HC595? It requires 3 pins from your RPI and you can control 8 output lines. You can easily cascade them effectively controlling n×8 output lines.

Data is serially clocked into the shift register and once all 8 output bits are transferred, you latch the bits onto the outputs.

I was about to add the datasheet here, but https://www.sparkfun.com/products/733 shows a nice video and has a link to the datasheet too.