In some cases, this issue is caused by a hardware fault. A loose connection, a short circuit, or a microscopic break in a solder joint may open and close depending on temperature, making the failure intermittent.
Please test after taking each of the following steps that you haven't already taken. Back up all data before making any changes.
1. Turn off Bluetooth. If you have a desktop Mac, you'll need a wired keyboard and mouse to take this step. Those are useful to have anyway, because Bluetooth is not completely reliable. If Wi-Fi works with Bluetooth turned off but not when you turn it back on, delete all pairings in the Bluetooth preference pane and recreate them. Restart the computer and test again.
2.. There are a few reports that the problem was solved by unchecking the box marked
Wake for Wi-Fi network access
in the Power Adapter tab of the Energy Saver preference pane. I can't confirm.
3. Reset the NVRAM.
4. Reset the System Management Controller.
5. Start up in Recovery mode. In the menu bar of the OS X Utilities screen, there's a Wi-Fi menu. Try to connect.
6. Triple-click anywhere in the line below on this page to select it:
/Library/Preferences/com.apple.Bluetooth.plist
Right-click or control-click the highlighted line and select
Services ▹ Reveal in Finder (or just Reveal)
from the contextual menu.* A folder should open with an item selected. Move the selected item to the Trash. You may be prompted for your administrator login password. Restart the computer and empty the Trash.
*If you don't see the contextual menu item, copy the selected text to the Clipboard by pressing the key combination command-C. In the Finder, select
Go ▹ Go to Folder...
from the menu bar and paste into the box that opens by pressing command-V. You may not see what you pasted because a line break is included. Press return.
7. Make a "Genius" appointment at an Apple Store, or go to another authorized service provider.