The most obvious way to look at the question is through the lens of sticky prices and/or costly price adjustment. In an economy where sticky prices are the predominant source of nominal rigidity, not only is price stability/inflation targeting optimal, it is consistent with NGDP targeting. This is because price stability in this economy is the exact same thing as output stability. If inflation is always equal to zero, then the costs of sticky prices and/or adjustment costs are minimized and output will perpetually be at potential. The combination of stable prices and stable output results in an outcome identical to targeting NGDP.
What type of nominal rigidity causes NGDP to be unstable under an inflation targeting regime then? The only answer I can come up with is nominal wage rigidity. If the nominal wage is adjusts slowly, then having a constant inflation rate will result in fluctuations in the labor supply and therefore output. Because of these fluctuations, it would be optimal for prices to adjust to whatever makes the real wage consistent with its natural level (the real wage consistent with full employment and no output gap). Of course, this means that having high inflation during a recession and low inflation during a boom, essentially NGDP targeting, is optimal.
So I guess the answer to the question in the title of this post is that it depends on what kind of frictions are present in the particular economy. If sticky prices dominate, then NGDP targeting is the exact same as price level or inflation targeting because a stable price level is synonymous with a stable level of output and, by extension, NGDP. If, however, nominal wage stickiness is the predominant source of nominal rigidity, then counter-cyclical inflation in necessary for NGDP stability and the optimal monetary policy for the economy.