Been a long time since I had them, but I've kept them with rams, apistos, curviceps, angelfish, discus, etc. Some of those-- discus, larger bodied angelfish, possibly curviceps due to limited territory for a similar size and shape fish-- might be tight and not work as well in a 40, but they're fish that are fine together in the right setting ime.
I keep bigger tanks than that and sometimes you see 40 gal and you think, hmm, small tank, but in terms of dimensions and territory it's basically a 55 with an inch or so nipped off here and there. Still, you are more limited by water volume so I'd be conservative and just make sure of your filtration and water managment.
Another possibility for me would be a nice shoal of cardinal tetras, which can really add a lot imo, color and even impact with a good shoal of them, especially with some plants in the tank. So, I'm just opining here, but for me I think I'd consider an apisto pair and some cardinals, all fish that like quieter waters. You'd just need to be on your game with water quality.