Hi there,
Normally I would go with two objects and use the boolean Object. You can turn that into a polygon object, by pressing the C key and then connect all parts.
Perhaps with simple shapes, it might be easier to *cut into the model to get more edges and pull the “cube”-like part out of the pyramid shape.
There are certainly more options, to get this kind of shape. A LatheNURBS set the subdivisions to four for example.
*cut, well, perhaps the primitive allows already for a subdivision, and you can select a bottom polygon and “Extrude” it.
Let me know if the example was just the target or a simplified version.
All the best
Sassi