Ok first off, if your running the training missions, do not use any of the mods. Many mods change the damage values of the game which can make it impossible to pass the tests.
Second with torpedoes. the head of the torpedo has to hit a nearly vertical flat surface if using the impact pistol. If they hit at too much of an angle and they will just bounce off (i suggest using the exterior view, and the action cam to see what's happening). Generaly you want to shoot when the angle on bow is close to 90 degrees (ie shooting at the side of the target ship).
With magnetics, the target needs to be a decent size, and you want to come with in 0.5-1m of the bottom (keel) of the ship to help insure detonation. Also the longer the torpedo is under the ship the better the chance it will detonate, so they are pretty much opposite to impact pistols as you will want to shoot when the aob is closer to 0 or 180 rather then 90 (though you dont have to).
Also if you want accurate shots, be sure you open your torp tubes first before firing or it can seriously throw off your shots.
Lastly set your steam torpedoes to maximum speed, that will give the target ships less time to escape.
As for guns, well main trick is to shoot just below the waterline (you know your doing it right if you see a shell splash in the water and then it detonating against the ship) best targets to shoot for is the engine room (right below the main funnel) or fuel bunker (typicaly in front of the engine room)
In general in the training missions you can be very agressive, stay on the surface chase down your targets at max speed. They dont exactly reflect real situations, and i never found it very usefull for practice. only to get the bonus renoun and learning the very basics.
As for optimum range, well its pretty much as close as you can get

. 250m is the actual arming distance, but it can fluctuate in game, which is why most captains shoot at 300m