Let's assume that we are simply trying to maximize the expected value of our roll. (As discussed this might not be a realistic representation of actual gameplay, but we can work it out anyway.) Then the rolls on any of the dice don't affect our decisions to reroll for other dice - that is, any one die's rolls and strategy is independent of other dice and we can work out expected value as the expected value for one die times the number of dice.
Now for the expected value of a N-sided die with R rerolls, we can establish a recurrence relation.
Starting with 0 rerolls, this is the normal expected value for a single die:
$$ E = \dfrac{1+N}{2} $$
Given \$E\$ as the expected value for R rerolls, we calculate \$E'\$ for R+1 rerolls:
$$ E' = P(reroll) \cdot E + P(keep) \cdot (average keep) $$
Now the decision to reroll is based on whether our expected value with R rerolls is higher than our current roll. Let \$\lfloor{E}\rfloor\$ be the floor of \$E'\$ (i.e. \$E'\$ rounded down to the nearest whole number - the highest number we will want to reroll), then:
$$
P(reroll) = \dfrac{\lfloor{E}\rfloor}{N} \\
P(keep) = \dfrac{N-\lfloor{E}\rfloor}{N} \\
\text{Average keep} = \dfrac{\lfloor{E}\rfloor+1 + N}{2}
$$
This gives us a formula for R+1 rerolls:
$$
\begin{align}
E' &= \dfrac{E\lfloor{E}\rfloor}{N} + \dfrac{(N-\lfloor{E}\rfloor)(N+\lfloor{E}\rfloor+1)}{2N} \\
&= \dfrac{2E\lfloor{E}\rfloor + (N-\lfloor{E}\rfloor)(N+\lfloor{E}\rfloor+1)}{2N}
\end{align}
$$
With an \$\lfloor{E}\rfloor\$ in our final formula, we can't get a nice closed form for any number of rerolls, but we can just calculate the values from the recurrence relation. For example, for your example with \$N=10\$:
$$
\begin{align}
E[\text{0 rerolls}] &= 5.5 & (\lfloor{E}\rfloor=5) \\
E[\text{1 reroll}] &= \dfrac{55 + 80}{20} = 6.75 & (\lfloor{E}\rfloor=6) \\
E[\text{2 rerolls}] &= \dfrac{81 + 68}{20} = 7.45
\end{align}
$$
For 3D10 with 2 rerolls our expected value is \$(3 \times 7.45) = 22.35\$. Our strategy is to reroll all values 1-6 on our first roll, reroll all values 1-5 on our second roll.