You can use a 40 for cichlids but there is just some you can't put in. and if you have HOB filters sand will wreck them. Cichlids to stay away from in a 40G are Jack Dempeys, Oscars, Green Terrors, Blood Parrots, Jewel Cichlids, Pike Cichlids, Texas Cichlids, Chocolates, Severums. Those are the most popular at pet stores. You could do OB peacocks, Yellow tail Aceis, species 44 and others similar, they normally stay around 5 inches and you can get the odd male that might hit 6-7''
You can overstock cichlid tanks and I actually recommend it, it gives the fish over the shoulder syndrome (patent pending haha). When the tank is packed I find my cichlids don't pick on each other as much, they are constantly doing 180's to see if another fish is behind them.
When cichlids get aggressive and chase another less dominate fish through the tank, having a crowd of fish and good decor will help. The fish being chased gets lost in the crowd/decor and goes on its way.
It all sounds good but there are downfalls. Extra filtration, excess water changes, lots of rock and hiding places.
I hope this helps, cichlids are awesome fish and hardly ever dull in the tank.