I don't yet have dwarf cichlids... but I have researched them, cycled their 55 Gal aquarium, and they are being ordered Monday and will be in tank by end of week...
From what I gathered 20 Gal per pair is what you are looking for. Some people say they have a pair in a 10 Gal successfully, but to go with 4 males in a 40 Gal the territorial battles will get very aggressive. Also many people suggest having a harem instead of a pair (which means 2-3 females per male). So with a 40 Gal you may want to consider a harem of each (Rams and Cockatoos). This way you won't have the males clashing over territories, but will still have enough fish in the tank it doesn't seem empty.
Regarding guppies... I cycled my 55 Gal (which I plan to stock with 3 Male / 6 female Cockatoos) with 150 guppies and since I started several have had babies and several more are pregnant. I will leave about 50 of the guppies in there and let the Cockatoos eat the fry as 'snacks'. I have a different tank which also has a bunch of guppies where I house a Black Ghost Knife and 2 severums (all babies). About every 3 or 4 days a female guppy has fry and the fish pick them off over the course of a day. If you are comfortable using guppy fry as food this system works perfect, as the cichlids aren't big enough to eat the breeding guppies, but can eat the fry. This way you don't have to worry about the 'source' (parent guppies) of the 'food' (fry) getting 'damaged' (eaten).
Also just to share my experience… I first wanted a Ram / Cockatoo mix in my 55 Gal. During research I learned that there is a chance the Rams & Cockatoos could cross breed, which I didn’t want. I also learned that it is very likely that different strains of Cockatoos will cross breed (strains such as double red, orange flash, etc). I also didn’t want this. At the end of my research and consideration I chose to go with an all Triple Red Cockatoo species set up. I’m not suggesting you do this, simply giving you some food for thought.
From all I’ve learned about dwarfs they are amazing fish much different than the larger cichlids I’m familiar with. I’m very much looking forward to watching them grow and develop. I’m sure you’ll end up with a great experience from them.
-Toby