Run the lowest octane your engine will tolerate without pinging. Run a tank or two of 87 octane. Does it ping under hard acceleration? If no, continue running 87 octane. If yes, go to the next higher octane. Repeat until there is no pinging under hard acceleration.
You can retard the timing a bit to make the engine more tolerant of the lower octane too, at some small cost to performance. But your wallet will be happy.