The omission of "of" when used as in your question is slang, so it's unlikely to make much sense. I'm going to try to make up some rules anyway. Please tear them down; if they're too wrong I'll improve them.
The meaning numbers below (e.g. 1.4) are referencing Wiktionary.
If the meaning is 1.3, 1.4, 2.1, 2.2, 2.3 (where it would change the meaning), 3.1 (where it might change the meaning), 3.2, 3.3 (where it might change the meaning), all of 4, all of 5 (especially 5.5, where its omission can cause any following indefinite article ("a" / "an") to mean "each" or "per"), all of 6, 7.2, 7.4, 8.2, 10.2 (you can't really... but it'd be interesting to see if the "exceptions" have a rule-like pattern)
Rule-like assertions:
If the meaning is 7.1, like in your question, you can omit "of" if:
- (colloquial) The word following "of" is an article and the word preceding "of" is an indefinite pronoun in this list:
- both
- all
- half
- there are probably more...
- The noun following the article is plural and you remove the article.
If the meaning is 8.1, 8.3 or 9.1, you can omit "of" if:
- You reverse the two noun phrases either side of "of" and it remains grammatically correct.
If the meaning is 10.1, you can omit "of" if:
- You convert the second noun to its adjectival form (e.g. "body" → "bodied," "leg" → "legged") and put a hyphen ("-") in between.
If the meaning is 10.3, you can omit "of" if:
- You remove the noun phrase preceding "of" (e.g. "at a speed of 40 m/s" → "at 40 m/s").
CAVEATS:
- This removes information.
- This can be confused with 8.3 (e.g. "at the speed of sound").
You can always remove it without changing anything else if the meaning is:
Conclusions:
- There are no complete rules about that can be described using English itself.
- English is horrible. What were we thinking?!