I agree with Wombat, substantial reading is in order. It's not so simple as reaching the optimal AFR. The piston is connected to the rod and acts as lever, there is a angle to the rod that corresponds to the point of greatest torque potential, known as maximum brake torque (MBT). MBT moves around with RPM, not for any physical reason (MBT should be constant if all revolutions are the same), but because at different RPM the time for combustion/exhaust varies and the heat generated varies (hotter cylinder means faster burning fuel, that needs less ignition advance). How the MBT varies is something that you'll have to determine with testing, but there are some general rules for the subarus. It helps to remember that the fuel is ignited while the piston is moving up toward the head, slower burning fuel (i.e. cooler cylinder or higher octane) gives more power with more advanced ignition (the burn starts earlier, but pushes with the most torque at the same instance (MBT) that a hotter cylinder or lower octane fuel would).
Enter knock: knock more so than power often determines what you can achieve in terms of power. In the mid-RPM range you will not be able to achieve either best fuel or best timing from a theoretical stand point. It will be a trade off between adding fuel to prevent knock, or retarding ignition timing.
Early in the RPM range under full load you can run AFR up to stochiometric, one to save yourself fuel under cruise conditions, but also to use the heat generated to spool up the turbo. Once you are at stochiometric, varying the timing of the ignition will give you a feel for the MBT ignition timing, ~20 degrees advance. Using this ignition advance as a standard, you are going to try and match it as RPM increases, adding fuel if knock occurs.
Once you get into high RPMs, you can start to remove some fuel, and advance timing. At this point your car is barely able to complete the burn of fuel and get all the combustion products out of the cylinder. Plus it's hotter than hell. You are holding on to what ever power you can get above about 6000 RPM.
Lot's of other things can alter the mix, and timing, of the tune in your favor and these are the source of many modifications, most of which cool the air prior to the intake (larger intercoolers, water injection), but also improve flow of the exhaust (headers), or help to expel exhaust more completely (cams). And the list goes on....