I had a group of 7, 2m/5f that I kept in a 33L, which has the same foot print just not as tall.
They worked fine in that tank for about 1-1/2yrs till I sold them. If I was you I would try to keep 2 male with a few females. From my experience the males can be very aggressive, so you might end up with just one male after awhile. And give the female some cover for when the male starts acting up.
Their a great little fish with some intresting behaviors. If you have to net one out of the tank you will notice that they will hide under the sand with just their eye sticking out.
They can be extremely aggressive. I kept wild ones, and there is no chance they would thrive in anything less than a six foot tank, without reducing their numbers rapidly. The results I've seen for tank raised are mixed, some being quite aggressive, some less so. No matter the tank size, the more females you can get, the less he'll stress any particular individual.
I've found in the past the only way to keep the more aggressive species of Tanganyikan's is with the addition of Cyprichromis. Wether it be species of Callochromis, or Ventralis, Cyp's usually solve all problem's. A 40 gallon is a bit small for the two species to co-exist, so instead I would crowd the group of Callochromis in your 40. Instead of 7, start with a group of 10, 1.5in. juvie's. Down the road you may lose a few, but if all work's well you should be left with a nice group, good luck.