3 wires to tail light from bike = 1 tail 1 brake 1 ground. Can't remember colors off top of my head but very easy to figure if you got a test light. Ground test light to subframe, turn on key, 2 wires will be dead 1 will be hot, that is your tail light. Mark it tail. Apply either brake and check other 2 wires 1 of the 2 will be hot, that is your brake, mark it. Other is ground.
To determine which wires coming from tail light are which pretty much the same. First determine your ground, usually green or black. Once ground is determined hook ground from bike to light ground, then just use tail light wire from bike to check other 2 going to light, with key on touch hot tail light wire from bike to each of the 2 wires left coming from light one at a time, one will light it dimmer than other, brighter is the brake light wire,mark it. Last one left is tail light. Then it's just connecting ground ground brake brake tail tail and that's it.
Hope that easy enough to understand, really couldn't think of easier way to explain it. And if you happen to have or get a tail with integrated turn signals there will be usually 2 extra yellow wires coming from tail light and those just get connected to the hot wire from each turn signal from original turn signal lights, they dont use turn signal ground as they get their ground from tail/ brake ground since it is all integrated into 1 unit.