For {time-expression} can appear after a verb or adjective to indicate how long the action was done or how long the attribute described by the adjective lasted.
This is only one of the many meanings of for. Prepositions in English like in many other languages are overloaded with many meanings that you simply have to memorize or follow existing patterns to learn.
I walked for three hours
I was sad for a long time.
It is also possible to use the time expression as an adverbial clause, where it directly modifies a verb or adjective. This typically strongly implies that the activity or attribute modified lasted for that long. It can potentially look a little weird in writing when modifying an adjective but is usually OK in speech.
I walked three hours.
I was sad a long time.
Of X means from group/set named X or from a group/set that has one or more X's, among many other meanings.
Since all means every, it will automatically reference everything in a group. So the of is optional, but it's not wrong to use it if needed for emphasis, clarity, etc.