Looking at this rule…
Kicking Team ARTICLE 1 If a free kick goes out of bounds between the goal lines untouched by an inbounds player of Team B, it is a foul (AR 6-2-1-I-II and 4-2-1-III) PENALTY—Live-ball foul. Five yards from the previous spot; or five yards from the spot where the subsequent dead ball belongs to Team B; or the receiving team may put the ball in play 30 yards beyond Team A’s restraining line at the hash mark [S19].
Now here is your scenario:
On your scoring play our opponent commits a personal foul. That is penalized 15 yards from the succeeding spot, the 40 on the KO, so we kick off on the opponents 45.
The penalty for a kick off out of bounds is 30 yards from the restraining line, which is now the opponents 45. The 30 yd penalty puts the ball at their 15, a fair catch/touch back brings it to the 25. Why not kick it out of bounds?