How to use flat color shading with anti-aliasing for multi-materials? I've been searching a while now for a solution to render out a flat colored map for masking out objects in photoshop.

I found this very helpfull topic:
https://blenderartists.org/forum/showthread.php?387255-Surface-ID-Pass-in-Blender

Is there a way to combine this technique so that objects with the same material/object will use the same color?

The main benefit from this technique is that it's anti-aliased which makes it more suitable for masking.
Each material can have it's own Pass Index set up in the Properties Window > Material > Settings > Pass Index

If you set them up correctly after rendering, using a Compositor you can use an ID Mask node to mask out each part of the image according to material.

It can be directly from the Render Layers node or from an Image node through a multi layer file format like EXR.

See the Blender Manual on how to

You an then use the compositor to extract one mask for each material and save it as an image.

This technique has the advantage that since it uses a black and white mask for each layer pass you can get full anti-aliasing for each mask, without running the risk of 'ID Collision' when the mixed anti-aliased colors match a different object from another pass.