How long should you cook anchovy and anchovy paste to extract the most flavor?
This is completely personal opinion, but I do not believe it is possible to overcook anchovies when they are being used to add flavor to a dish. The optimal situation is that you cook the food long enough for the anchovies to completely break down. It is an entirely different issue when you actually want to serve them as a featured ingredient instead of a seasoning.

With either paste or whole/ chopped, it is impossible to undercook as both are ready to eat as sold, unless your anchovy can was ready to burst due to a little Gram-positive bowling-pin shaped spore-forming rod called Clostridium botulinum having some fun.

Getting to the actual questions, when using a paste it doesn't actually need any cooking, just stir it in and you are ready once it's incorporated. If you can't see the lump of paste you have successfully extracted the flavor.