R is allowed to keep the ball if it declines the foul on K. K then has the option to enforce either, but not both, penalties on R.
If R wants to enforce the illegal formation penalty, then it's a double foul and the down is replayed.
The point of the rule is to ensure that the fouls on R are after the change of possession, not before, and PSK fouls are treated as post-possession change even though R has not gained possession when the foul occurred. This situation does not apply if R commits "pre"-scrimmage kick fouls, for example, if the holding was at the line of scrimmage (not beyond the expanded neutral zone) or running into/roughing the kicker.