(Java Minecraft 1.14) How to save a player's scoreboard team temporarily for later use?
No, there is no simpler way, your solution is pretty close to what I would have done as well. You can't use team names, identifiers or colours in any dynamic way in Minecraft commands, so you would have to have commands per team anyway.
Make an AFK objective with "walk 1 cm" criteria. command is like this:
/scoreboard objectives add AFK minecraft.custom:minecraft.walk_one_cm
Make a SLOW redstone clock (don't use repeating command block because it's fast) something like 2 fully-delayed repeaters next to 2 other fully-delayed repeaters in opposite direction linked with redstone dust on both sides obviously. And then on one side you place a redstone line linked to an impulse command block with the following command
/scoreboard players remove @a AFK 10
So that players who are moving will always surpass the score-removing clock keeping them unable to reach 0 AFK score, but for the players who are not moving they might even get a negative score if they stand still and there comes the repeating command block(Always Active) that detects players with AFK score of 0 or less, you can place it anywhere, it doesn't have to be linked to the clock, and in it you write the following command:
/execute if entity @a[score={AFK=..0}] run /scoreboard players reset @a[score={AFK=..0}] AFK
That way you remove the players(with AFK score of 0 or less) from the score tracker (so that the score doesn't keep going down because the score-removing clock) and then you place a comparator facing the opposite direction that the repeating command block is facing and then place an impulse command block also facing the same direction as the previous components and in this command block you do whatever you wanna do to the AFK players. And don't worry about them not being tracked by the score tracker, they will be tracked again once they start moving and the clock will automatically start affecting them again
i hope this was helpful for you or any other one with the same problem.