If when it happens, you are sure that you dont have any power then it sounds like a bad electrical connection on the battery circuitry. Such as a bad battery ground, or battery cable connection.
Get a volt meter. Connect the negative directly to the battery post, then start by measuring the battery positive expecting about 12.8V.
Keep the positive terminal on the battery, and move the meter negative cable to the engine block, expecting a good ground there, you should also then see 12.8V or so on the meter.
If not then there is a bad ground, check the battery ground cable to the chassis.
Get a longer grounding wire, such as one jumper cable on the negative battery post. Use it as an extension of the ground so you can use it with your meter to probe the fuse panel in the dash, or relay box under the hood. Still expecting 12.8V or so. If it is good, then the positive battery cable to the fuse box is good.
So from your brief description, sounds like a bad battery ground, or bad connection near the battery.
Next time it occurs, turn on the headlights, and try to wiggle the battery cables. If the headlights turn on, then you found the bad connection.