How to use flat color shading with anti-aliasing for multi-materials?
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.