This is a bit complex…
Probably the closest code example I can give is this:
That the code that creates the checklist in the admin.
The related function being used is here:
And that calls a couple recursive functions for transversing the category tree and output the list.
It is come pretty old code that is going to be rewritten because it can be done better … but this should at least give you the idea of how to put this together. Hope it helps!